コード例 #1
0
ファイル: WaveBank.cs プロジェクト: kiates/FNA
        public WaveBank(
            AudioEngine audioEngine,
            string nonStreamingWaveBankFilename
            )
        {
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (String.IsNullOrEmpty(nonStreamingWaveBankFilename))
            {
                throw new ArgumentNullException("nonStreamingWaveBankFilename");
            }

            bankData = TitleContainer.ReadToPointer(
                nonStreamingWaveBankFilename,
                out bankDataLen
                );

            FAudio.FACTAudioEngine_CreateInMemoryWaveBank(
                audioEngine.handle,
                bankData,
                (uint)bankDataLen,
                0,
                0,
                out handle
                );

            engine        = audioEngine;
            selfReference = new WeakReference(this, true);
            engine.RegisterPointer(handle, selfReference);
            IsDisposed = false;
        }
コード例 #2
0
        public SoundBank(AudioEngine audioEngine, string filename)
        {
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

            IntPtr bufferLen;
            IntPtr buffer = TitleContainer.ReadToPointer(filename, out bufferLen);

            FAudio.FACTAudioEngine_CreateSoundBank(
                audioEngine.handle,
                buffer,
                (uint)bufferLen,
                0,
                0,
                out handle
                );

            FNAPlatform.FreeFilePointer(buffer);

            engine        = audioEngine;
            selfReference = new WeakReference(this, true);
            dspSettings   = new FAudio.F3DAUDIO_DSP_SETTINGS();
            dspSettings.SrcChannelCount     = 1;
            dspSettings.DstChannelCount     = engine.channels;
            dspSettings.pMatrixCoefficients = Marshal.AllocHGlobal(
                4 *
                (int)dspSettings.SrcChannelCount *
                (int)dspSettings.DstChannelCount
                );
            engine.RegisterPointer(handle, selfReference);
            IsDisposed = false;
        }
コード例 #3
0
        public AudioEngine(
            string settingsFile,
            TimeSpan lookAheadTime,
            string rendererId
            )
        {
            if (String.IsNullOrEmpty(settingsFile))
            {
                throw new ArgumentNullException("settingsFile");
            }

            // Allocate (but don't initialize just yet!)
            FAudio.FACTCreateEngine(0, out handle);

            // Grab RendererDetails
            ushort rendererCount;

            FAudio.FACTAudioEngine_GetRendererCount(
                handle,
                out rendererCount
                );
            if (rendererCount == 0)
            {
                FAudio.FACTAudioEngine_Release(handle);
                throw new NoAudioHardwareException();
            }
            rendererDetails = new RendererDetail[rendererCount];
            byte[] converted = new byte[0xFF * sizeof(short)];
            for (ushort i = 0; i < rendererCount; i += 1)
            {
                FAudio.FACTRendererDetails details;
                FAudio.FACTAudioEngine_GetRendererDetails(
                    handle,
                    i,
                    out details
                    );
                unsafe
                {
                    Marshal.Copy((IntPtr)details.displayName, converted, 0, converted.Length);
                    string name = System.Text.Encoding.Unicode.GetString(converted).TrimEnd('\0');
                    Marshal.Copy((IntPtr)details.rendererID, converted, 0, converted.Length);
                    string id = System.Text.Encoding.Unicode.GetString(converted).TrimEnd('\0');
                    rendererDetails[i] = new RendererDetail(name, id);
                }
            }

            // Read entire file into memory, let FACT manage the pointer
            IntPtr bufferLen;
            IntPtr buffer = TitleContainer.ReadToPointer(settingsFile, out bufferLen);

            // Generate engine parameters
            FAudio.FACTRuntimeParameters settings = new FAudio.FACTRuntimeParameters();
            settings.pGlobalSettingsBuffer    = buffer;
            settings.globalSettingsBufferSize = (uint)bufferLen;
            settings.globalSettingsFlags      = FAudio.FACT_FLAG_MANAGEDATA;
            xactNotificationFunc            = OnXACTNotification;
            settings.fnNotificationCallback = Marshal.GetFunctionPointerForDelegate(
                xactNotificationFunc
                );

            // Special parameters from constructor
            settings.lookAheadTime = (uint)lookAheadTime.Milliseconds;
            if (!string.IsNullOrEmpty(rendererId))
            {
                // FIXME: wchar_t? -flibit
                settings.pRendererID = Marshal.StringToHGlobalAuto(rendererId);
            }

            // Init engine, finally
            if (FAudio.FACTAudioEngine_Initialize(handle, ref settings) != 0)
            {
                throw new InvalidOperationException(
                          "Engine initialization failed!"
                          );
            }

            // Free the settings strings
            if (settings.pRendererID != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(settings.pRendererID);
            }

            // Init 3D audio
            handle3D = new byte[FAudio.F3DAUDIO_HANDLE_BYTESIZE];
            FAudio.FACT3DInitialize(
                handle,
                handle3D
                );

            // Grab channel count for DSP_SETTINGS
            FAudio.FAudioWaveFormatExtensible mixFormat;
            FAudio.FACTAudioEngine_GetFinalMixFormat(
                handle,
                out mixFormat
                );
            channels = mixFormat.Format.nChannels;

            // All XACT references have to go through here...
            notificationDesc       = new FAudio.FACTNotificationDescription();
            notificationDesc.flags = FAudio.FACT_FLAG_NOTIFICATION_PERSIST;
            notificationDesc.type  = FAudio.FACTNOTIFICATIONTYPE_WAVEBANKDESTROYED;
            FAudio.FACTAudioEngine_RegisterNotification(
                handle,
                ref notificationDesc
                );
            notificationDesc.type = FAudio.FACTNOTIFICATIONTYPE_SOUNDBANKDESTROYED;
            FAudio.FACTAudioEngine_RegisterNotification(
                handle,
                ref notificationDesc
                );
            notificationDesc.type = FAudio.FACTNOTIFICATIONTYPE_CUEDESTROYED;
            FAudio.FACTAudioEngine_RegisterNotification(
                handle,
                ref notificationDesc
                );
        }