Example #1
0
        public WaveAudioPlayer(WaveOutputPort outPort, WaveFile aFile)
        {
            fOutPort = outPort;
            fWaveFile = aFile;

            //fOutHdr = WAVEHDR.CreateWithLength((int)fWaveFile.fData.dwChunkSize);
            fOutHdr.dwFlags = 0;
            fOutHdr.dwLoops = 0;

            // Copy the bytes to the fixed memory
            // BUGBUG - need to allocate the memory
            //fOutHdr.lpData = fMemHandle;
            Marshal.Copy(fWaveFile.fData.byteArray, 0, fOutHdr.lpData, (int)fWaveFile.fData.dwChunkSize);

            //fOutPort.PrepareHeader(fOutHdr);
        }
Example #2
0
        /// <summary>
        /// Help the user create an output device by specifying a few key parameters.
        /// </summary>
        /// <param name="deviceID"></param>
        /// <param name="channels"></param>
        /// <param name="sampleRate"></param>
        /// <param name="bitsPerSample"></param>
        /// <returns></returns>
        public static WaveOutputPort CreateOutputPort(int deviceID, int channels, int sampleRate, int bitsPerSample)
        {
            int bytesPerSample = bitsPerSample / 8;

            WAVEFORMATEX wfx = WAVEFORMATEX.CreatePCMFormat(channels, sampleRate, bitsPerSample);

            // Query to see if the specified format is supported
            IntPtr tmpHandle = new IntPtr();
            MMSYSERROR result = winmm.waveOutOpen(ref tmpHandle, deviceID, wfx, null, IntPtr.Zero, winmm.WAVE_FORMAT_QUERY);

            // If there was any error, return null
            if (winmm.MMSYSERR_NOERROR != result)
                return null;

            WaveOutputPort outPort = new WaveOutputPort(deviceID, wfx);
            
            return outPort;
        }