Click here to Skip to main content
15,886,689 members
Articles / Game Development

Sound in games - Rooms

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
31 Jul 2012CPOL16 min read 31.5K   571   14  
How to calculate a reverbration time in a room
<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   
            xmlns:am="http://schemas.amcharts.com/charts/wpf/2009/xaml"
    Title="MainWindow" Height="878" Width="850" Background="LightGray" >
    <StackPanel Background="LightGray" >
        <TabControl Height="831" Background="LightGray"  >
            <TabItem Name="tabInput" Header="Input data">
                <StackPanel>
                    <Label>This program calculates the reverberation time in a rectangular room</Label>
                    <WrapPanel>
                        <Label Width="210">Enter the hight of the room (z-axis):</Label>
                        <TextBox Name="txtHeightRoom" Width="100" BorderBrush="Black" BorderThickness="2"></TextBox>
                        <Label Width="100">Humidity in %:</Label>
                        <TextBox Name="txtHumidityRoom" Width="45" BorderBrush="Black" BorderThickness="2" Text="20"></TextBox>
                    </WrapPanel>
                    <WrapPanel>
                        <Label Width="210">Enter the width of the room (y-axis):</Label>
                        <TextBox Name="txtWidthRoom" Width="100" BorderBrush="Black" BorderThickness="2"></TextBox>
                    </WrapPanel>
                    <WrapPanel>
                        <Label Width="210">Enter the length of the room (x-axis):</Label>
                        <TextBox Name="txtLengthRoom" Width="100" BorderBrush="Black" BorderThickness="2"></TextBox>
                    </WrapPanel>
                    
                    <Label>Absorbers in Z direction</Label>
                    <ListView Height="150" Name="lstZ">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Width="500" Header="Absorber name">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Name}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Width="140" Header="Amount (m2)">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Area}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <WrapPanel>
                        <Button Name="btnZabsorbers" Height="28" Margin="5" IsEnabled="False" >Add absorbers in Z direction</Button>
                        <Label>Floor and ceiling area:</Label>
                        <Label Name="lblZarea"></Label>
                    </WrapPanel>


                    <Label>Absorbers in Y direction</Label>
                    <ListView Height="150" Name="lstY">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Width="500" Header="Absorber name">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Name}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Width="140" Header="Amount (m2)">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Area}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <WrapPanel>
                        <Button Name="btnYabsorbers" Height="28" Margin="5" IsEnabled="False" >Add absorbers in Y direction</Button>
                        <Label>Area of side walls:</Label>
                        <Label Name="lblYrea"></Label>
                    </WrapPanel>


                    <Label>Absorbers in X direction</Label>
                    <ListView Height="150" Name="lstX">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Width="500" Header="Absorber name">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Name}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Width="140" Header="Amount (m2)">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Label  Content="{Binding Path=Area}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <WrapPanel>
                        <Button Name="btnXabsorbers" Height="28" Margin="5" IsEnabled="False" >Add absorbers in X direction</Button>
                        <Label>Area of front and back walls:</Label>
                        <Label Name="lblXrea"></Label>
                    </WrapPanel>

                    
                    <Button Name="btnCalculate" Margin="10">Calculate reverbration time</Button>
                </StackPanel>
            </TabItem>
            <TabItem Name="tabResult" Visibility="Visible"   Header="Calculation results" Background="LightGray">
                <StackPanel>
                    <WrapPanel>
                        <Label Content="Schroeder frequency:" Margin="5"></Label>
                        <Label Name="lblSchroder" Margin="5"></Label>
                    </WrapPanel>
                    <WrapPanel>
                        <Label Content="Room radius:" Margin="5"></Label>
                        <Label Name="lblRoomRadius" Margin="5"></Label>
                    </WrapPanel>

                    <am:LineChart Name="chrt2" LegendEnabled="True" IsZoomable="True" Margin="10" PlotAreaMargin="50,20,30,70" Background="White" Foreground="Black" ConnectOverGaps="True"  HorizontalContentAlignment="Left"  Width="785" Height="420">
                        <am:LineChart.CategoryAxis>
                            <am:CategoryAxis ValuesEnabled="True" Stroke="Black" StrokeThickness="1"  ValuesRotationAngle="30"  ValuesFontSize="9" ValuesInside="False" />
                        </am:LineChart.CategoryAxis>

                        <!--<am:LineChart.LeftValueAxis>
                            <am:ValueAxis ValuesFormatString="0' dB'" StrictMinMax="True" StrokeThickness="1" SkipFirstValue="False" Minimum="0" Maximum="80" />
                        </am:LineChart.LeftValueAxis>-->

                        <am:LineChart.LeftValueAxisGrid>
                            <am:ValueGrid Stroke="Gray" StrokeThickness="1.1" CountHint="10"/>
                        </am:LineChart.LeftValueAxisGrid>
                    </am:LineChart>
                    <ListView Margin="10"  Name="lstResult" ItemsSource="{Binding}" Height="175">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="190" Header="Formula" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=Name}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                     
                            <GridViewColumn Width="60" Header="31Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f31Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="63Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f63Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="125Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f125Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="250Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f250Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="500Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f500Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="1000Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f1000Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="2000Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f2000Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="4000Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f4000Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="8000Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f8000Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="60" Header="16000Hz">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Label Content="{Binding Path=f16000Hz}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
                </StackPanel>
            </TabItem>
        </TabControl>
    </StackPanel>
 
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions