Quantcast
Channel: NAudio
Viewing all 5831 articles
Browse latest View live

Commented Issue: ComException when unplugged playback device [16329]

$
0
0
When playbackdevice disapears from windows playback devices (when user unplugs device from usb or audio jack port or disable it) while playling file, an COMException occrus in DirectSoundOut.StopPlayback() method on line 475: secondaryBuffer.Stop();

I don't know if it is possible to handle the exception from wpf application since it is in another thread.

I attached working sample project. just click the play button and unplug the device. if there's more than one playback device, then disable them. Exception occurs only when last device is disabled/uplugged.

You have a try..catch..finally bock in PlaybackThreadFunc, but when an exception is caught, then you call the com methods in finally block without try catch. You should at least use try..catch(ComException).


System.Runtime.InteropServices.COMException was unhandled
Message=Exception from HRESULT: 0x88780096
Source=NAudio
ErrorCode=-2005401450
StackTrace:
at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop()
at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 475
at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Admin\Desktop\NAudio\naudio_db92aece4b2f\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 442
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Comments: I recently got this exception running [2339a04e76cc](https://naudio.codeplex.com/SourceControl/changeset/2339a04e76cc) from March 28, 2013. It was after recently switching from WaveOut to DirectSoundOut (which works a lot faster with super low latency!!!) Exception Type: System.Runtime.InteropServices.COMExceptionException Message: Exception from HRESULT: 0x88780096 Stack Trace: at NAudio.Wave.DirectSoundOut.IDirectSoundBuffer.Stop() at NAudio.Wave.DirectSoundOut.StopPlayback() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 485 at NAudio.Wave.DirectSoundOut.PlaybackThreadFunc() in C:\Users\Brandon\Projects\RemoteHams.com\NAudio\Wave\WaveOutputs\DirectSoundOut.cs:line 446 at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() I see that line 446, as in the crash report, follows the report above. StopPlayback is called in a finally statement without exception handling. Making it difficult for the calling application to capture the exception. I will try the suggested fix and see if that helps prevent any further exceptions and report back here.

New Post: Analyze Music pulses

$
0
0
Hi There.
I wanna Realize for instance the peak of the particular music and something like that. Get data from any part of the music in which for example what is the highest pulse is in this second and what is the lowest.
Can I get some data like that with NAudio?
You know, I just don't have any experience in signal analyzing or working on music signals so Would you please guide me in this purpose?
Thanks in advance.

New Post: NAudio - audio visualizer C#

$
0
0
Hi. Can anyone explain what is the logic behind an audio visualizer and how can I use NAudio to make a simple visualizer ? I supose I need to make use of NAudio.Wave and analize the waveform created ... but then ?

New Post: Finding Pattern sound inside another stream

$
0
0
I need to find a pattern inside the wave stream/file

Scenario:

I have a wave file #1 with N sentences, I need to find based on another wave file #2 if there is a match.

Example:

File #1:
Hi every body, I would like to kill everyone in this room.

File #2:
kill

So when I process the file I will check in there is a "kill" on the File#1

Does anybody have an idea to aproach this process?

New Post: 32 to 16 bit depth wav help needed

$
0
0
Hi !

I have problem with audio recording from WasapiLoopbackCapture, its record wav file with 32 bit depth even when i set in sound card to 16 bit. I need 16 bit to mix it dow with other wav file (of course with 16 bit depth) i can manage how to do this. Please help

Here is a code part:
waveOut = new WasapiLoopbackCapture();
...
if (waveIn.WaveFormat.BitsPerSample == 32)
{
       flag_321 = true;
}
...
writer2 = new WaveFileWriter(Path.Combine(LocaloutputFolder, LocaloutputOut_wav), waveOut.WaveFormat);

waveOut.DataAvailable += new EventHandler<WaveInEventArgs>(OnDataAvailable1);
waveOut.StartRecording();

public static void OnDataAvailable1(object sender, WaveInEventArgs e)
{
if (writer2 != null)
{
    writer2.Write(e.Buffer, 0, e.BytesRecorded); <--- I think i can change bit depth here but i can't manage how
}
}


New Post: how to decode mp3 byte[] from socket

$
0
0
I am newer to NAudio,i have a mp3 url likes : http://www.abc.com/sample.mp3
and want to download it with socket and store it into byte[] .code likes
quequ<byte[]> _queue;
......

    nBytes = _socket.Receive(recvBuffer, 0, 10240, SocketFlags.None);
    _queue.Enqueue(recvBuffer);

......
I read the demo code of Mp3StreamingDemo and know that Mp3Frame should be used to decode,but it always null.
what should i do?can some one helps me.

New Post: Wasapi Loopback Recording -> Heavy noise/distortion

$
0
0
**markheath wrote:**
You do need to get the right WaveFormat - using the one from capture should be OK, although WASAPI annoyingly likes to use WAVEFORMATEXTENSIBLE, so often I turn that into the equivalent PCM or IEEE Float WAVEFORMAT.
Can you give an example how did to achive this ?

New Post: Wasapi Loopback Recording -> Heavy noise/distortion

$
0
0
well for example if the WAVEFORMATEXTENSIBLE contained stereo IEEE float at 44.1kHz, you'd do this to make an equivalent WAVEFORMAT:
WaveFormat.CreateIEEEFloat(44100, 2);

New Post: how to decode mp3 byte[] from socket

$
0
0
either it doesn't contain an MP3 file, or there is not a complete MP3 frame in there.

New Post: 32 to 16 bit depth wav help needed

New Post: NAudio - audio visualizer C#

$
0
0
I'd recommend starting by looking at the demo projects that come with NAudio. They show how to draw waveforms and use FFT for spectrum analyser

New Post: 10 band Equalizer

$
0
0
you can't reassign buffer in the Read method. You must write into the buffer you were passed

New Post: NAudio 1.7-alpha MediaFoundationReader

$
0
0
Hi, I have the following code to play aac format:
            var reader = new MediaFoundationReader("d:\\Projects\\Samples\\aac.aac");

            var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
            var outDevice = CmbDevices.SelectedItem as OutDevice;
            if (outDevice != null)
                waveOut.DeviceNumber = outDevice.DeviceId;
            _waveOut = waveOut;
            _waveOut.Init(reader);
            _waveOut.PlaybackStopped += WaveOutOnPlaybackStopped;
            _waveOut.Play();
But song playing only 1 second and after this StopPlayBack event is raised with Excaption. There no such problem with mp3 and Mp3FileReader. Also with WaveCallbackInfo.NewWindows() also everything works fine.

The exception is
Exception = {"Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.MediaFoundation.IMFSourceReader'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70AE66F2-C809-4E4F-8915-BDCB406B7993...
I found this post in StackOverflow:
http://stackoverflow.com/questions/1233468/unable-to-cast-com-object-of-type-exception
but seems to me that it isn't the case because IMFSourceReader has ComImport with correct Guid.
Please help me to figure out with this issue.
Thanks, Roman

New Post: NAudio 1.7-alpha MediaFoundationReader

$
0
0
I'd stay away from function callbacks if at all possible. Use WaveOutEvent if you want a background thread for audio playback.

New Post: NAudio - audio visualizer C#


New Post: NAudio 1.7-alpha MediaFoundationReader

$
0
0
Thanks Mark,

So, if I understand you correct I need to do the following:

Use this:
var waveOut = new WaveOutEvent();
Instead of this:
var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
for background thread audio playback, right?

New Post: 24 bit to 16 bit on the fly

$
0
0
Hi !

I need help with converting 24 bit input to 16 bit "on the fly" im trying to record audio output, if the format is set to 24 bit depth i have problem with mix it down to one channel (sound is slower) here is the example wchich im using to convert if audio has 32 bit i dont know how to change this code if input has 24 bit
                            byte[] newArray16Bit = new byte[e.BytesRecorded / 2];
                            short two;
                            float value;
                            for (int i = 0, j = 0; i < e.BytesRecorded; i += 4, j += 2)
                            {
                                value = (BitConverter.ToSingle(e.Buffer, i));
                                two = (short)(value * short.MaxValue);

                                newArray16Bit[j] = (byte)(two & 0xFF);
                                newArray16Bit[j + 1] = (byte)((two >> 8) & 0xFF);
                            }
                            byte[] mono = StereoToMono(newArray16Bit);
                            OutFile.Write(mono);
i found sample code to convert but it returns float[] i need byte:
public float[] Convert24BitToFloat(byte[] input)
{
    int inputSamples = input.Length / 3; // 24 bit input
    float[] output = new float[inputSamples];
    int outputIndex = 0;
    var temp = new byte[4];
    for(int n = 0; n < inputSamples; n++)
    {
        // copy 3 bytes in
        Array.Copy(input,n*3,temp,0,3);
        int sample = BitConverter.ToInt32(temp,0);
        output[outputIndex++] = sample / 16777216f;
    }
    return output;
}

New Post: Can you customize it to work with silverlight 4.0?

$
0
0
hi markheath:
Is there possible that NAudio could work with MediaElement. I mean NAudio could parser audio files to a kind of MediaStreamSource?
I have a sort of non-pcm wav files (Intel IMA ADPCM), do u have any ideas that I could play wav over silverlight? This problem really piss me off.

New Post: Loud noise at the beginnig and at at the end of a stream with WaveOut.Play()

$
0
0
Hi i have similar problem .
i have 2 WaveProvider32 (sine providers) that pass to MultiplexingWaveProvider that pass to MultiplexingWaveProvider32Stereo,
the MultiplexingWaveProvider32Stereo looks like that:
    public int Read(byte[] buffer, int offset, int count)
    {                    
        int sampleRead = m_MultiplexingWaveProvider.Read(buffer, offset, count);
        WaveBuffer waveBuffer = new WaveBuffer(buffer);

        if (m_WaveFileWriter != null)
        {
            for (int i = 0; i < sampleRead / 4; i++)
            {
                m_WaveFileWriter.WriteSample(waveBuffer.FloatBuffer[i]);
            }
        }            
        return sampleRead;            
    }
it means he read the buffer and also writing to file.
sometimes i get in the begining of the stream beeps that take 5-10 seconds .
what i do wrong?

New Post: Can you customize it to work with silverlight 4.0?

$
0
0
yes, it is possible to turn a MediaElement into an IWavePlayer, but I haven't done it myself. You'd also need a completely managed decoder for your ADPCM, since Silverlight cannot access ACM codecs.
Viewing all 5831 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>