Click here to Skip to main content
15,896,118 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.7K   571   14  
How to calculate a reverbration time in a room
Imports Microsoft.Office.Interop

Public Class frmAbsorber
    Private Abs As Absorber
    Private temp As New System.Collections.ObjectModel.ObservableCollection(Of Absorber)

    Private ImportedFromExcel As New System.Collections.ObjectModel.ObservableCollection(Of Absorber)

    Private Function GetParent(ByVal path As String) As String
            Dim directoryInfo As System.IO.DirectoryInfo
            directoryInfo = System.IO.Directory.GetParent(path)
            Return directoryInfo.FullName
    End Function

    Public Sub New(ByRef _Abs As Absorber)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Abs = _Abs
        temp.Add(Abs)
        lstAbs.ItemsSource = temp
        Dim path As String = GetParent(GetParent(System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)))
        Dim filename As String = path & "\AbsorberList.xlsx"

        ' Create new Application.
        Dim excel As Excel.Application = New Excel.Application

        ' Open Excel spreadsheet.
        Dim w As Excel.Workbook = excel.Workbooks.Open(filename)
        Dim sheet As Excel.Worksheet = w.Sheets(1)
        Dim usedRange As Excel.Range = sheet.UsedRange

        Dim darray(,) As Object
        darray = CType(usedRange.Value, Object(,))

        Dim rows As Integer = darray.GetUpperBound(0)
        Dim cols As Integer = darray.GetUpperBound(1)
        For ii As Integer = 2 To rows
            Dim g As New Absorber
            For j As Integer = 1 To cols
                If j = 1 Then
                    g.Name = darray(ii, j).ToString
                ElseIf j > 1 Then
                    g.SetItem(j - 2, CDbl(darray(ii, j).ToString))
                End If
            Next
            ImportedFromExcel.Add(g)
        Next
        w.Close()

        For i As Integer = 0 To ImportedFromExcel.Count - 1
            cmbSelectFromExcel.Items.Add(ImportedFromExcel(i).Name)
        Next

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Abs.Name = temp(0).Name
        Abs.Area = temp(0).Area
        For i As Integer = 0 To temp(0).Count - 1
            Abs.SetItem(i, temp(0).GetItem(i))
        Next
        Me.DialogResult = True
        Me.Close()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Me.DialogResult = False
        Me.Close()
    End Sub

    Private Sub cmbSelectFromExcel_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles cmbSelectFromExcel.SelectionChanged
        Dim something As New Absorber
        something = ImportedFromExcel(cmbSelectFromExcel.SelectedIndex)
        temp(0) = something
    End Sub
End Class

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