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

New Post: I'm lost, help appreciate

$
0
0
Yes, put them through a WaveToSampleProvider and then they can be added to a MixingSampleProvider assuming they all share a common format

New Post: Clicking noise while changing volume/pan

$
0
0
markheath wrote:
why are you doing interlocked increments in your Read method. Taking many thousands of locks every second is not going to perform well. I'd also copy the NormFactor into a local variable to save repeated property gets.
Um, funny story behind that:-)
Having borrowed the PanningSampleProvider, and not reading C# very well, I converted it to VB with Telerik which translated "buffer[outIndex++] = " to "buffer(System.Math.Max(System.Threading.Interlocked.Increment(outIndex), outIndex - 1)) ="

Anyway, fixed that so my code is now simply:
For n As Integer = 0 To sourceSamplesRead - 1
            buffer(outIndex) = lpan * Me.sourceBuffer(n) * (m_volume * NormFactor)
            buffer(outIndex + 1) = rpan * Me.sourceBuffer(n) * (m_volume * NormFactor)
            outIndex += 2
        Next n
Totally still getting those subtle glitches whenever I move the pan or volume knobs though :(
(Or move the form)
Incidentally, that NormFactor is just a variable, calculated only once when the user toggles Normalization on or off.

New Post: waveout get notification after elapsed time

$
0
0
Hi,

i am working on a project where i need to play an audiofile (mp3) and after a specific amount of time i need to trigger some kind of a signal. Therefore i wrote my own AudioFileReader.
    public class TimeElapsedAudioFileReader : AudioFileReader
    {
        public event Action<TimeSpan> Elapsed;

        public TimeElapsedAudioFileReader(string filename):base(filename)
        {
            
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            if (Elapsed != null)
                Elapsed(this.CurrentTime);
            return base.Read(buffer, offset, count);
        }
    }
The Problem with that approach is that it is not precise enough. I wanna have the elapsed Signal triggered after each millisecond for example, therefore i thought i have to set the buffersize that is read but i cant find anything to set the buffersize. Maybe I am wrong with my thoughts? Hope for help!

KR Manuel

New Post: Changing AudioFileReader.Position while paused caused garbled output

$
0
0
I am doing MP3 playback using AudioFileReader and WaveOut.

I am able to set AudioFileReader.Position in code while a song is playing, and it works great. The playback jumps to the new position and continues without missing a beat.

However, if I call WaveOut.Pause(), then change AudioFileReader.Position, then call WaveOut.Resume(), the playback resumes, but the output is garbled. If I don't change the position in between the Pause() and Resume(), everything is fine. It's only the specific case of Pause() -> change Position -> Resume() that cause the garbled playback.

Is this a known bug, or am I doing something wrong?

-Joe

New Post: Changing AudioFileReader.Position while paused caused garbled output

$
0
0
Try to resume with "WaveOut.Play()" instead of "WaveOut.Resume()". I think this is might be an old WaveOut issue.

New Post: Playing Audio on several soundcards

$
0
0
Hi, is there any way to play a WaveStream on many soundcards at the same time?

I actually use code like this, but it introduces some delay I´d wish to remove:
Private Sub PlayOnAllSoundcards(Byval FilePath as String, Byval CardIDs() as Integer)
     For Each SoundcardID as Integer in CardIDs
         Dim SourceReader as new AudioFileReader(FilePath)
         Dim WaveOut as new WaveOutEvent() with {.DeviceNumber = SoundcardID}
         WaveOut.Init(SourceReader)
         WaveOut.Play()
     Next
End Sub
Creating multiple Reader and Output objects introduces obv. some latency. All inputs are in the Wformat (44100,2,16).

I´ve looked at your MultiplexingWaveProvider source as you wrote in your article, it would send output to several soundcards, but it still has only one Read method - therefore not usable to Init in many WaveOut objects. Right?

My questions in detail:

So how to play audio professionally on several soundcards?

And how to set channel matrices (for virtual surround sound) like CSCore does?

Thanks in advance, it would pretty much boost my Media Player!

PS: I love NAudio architecture. And still reading your blog for NAudio news :)

New Post: Changing AudioFileReader.Position while paused caused garbled output

$
0
0
That worked, thanks! What is the difference between those two methods?

New Post: Changing AudioFileReader.Position while paused caused garbled output

$
0
0
Looking at the source the difference is, that "WaveOut.Resume()" is calling the native restart function without enqueueing buffers like "WaveOut.Play()".

New Post: waveout get notification after elapsed time

$
0
0
If you want a sample-precise approach, then I´d use NotifyingSampleProvider. There you can compare each sample with the current time of your AudioFileReader and raise an event if so.

New Post: Clicking noise while changing volume/pan

$
0
0
If that glitch happens with moving the form or clicking gui elements I suppose you use WaveOut instead of WaveOutEvent.

Anyway, why you work with two sample buffers (buffer and sourceBuffer)? Perhaps they are not in sync or the double copy takes too much cpu.

I can just guess for the lack of details here.

New Post: play/write audio to file after filtering

$
0
0
Call "WaveFileWriter.Dispose()" after writing to update, finalize and close the wav file. m4a is also for sure the false extension, it should be ".wav".

New Post: Volume Range of WaveOut

$
0
0
It should range from 0 to 65565 if I remember correctly.

New Post: waveout get notification after elapsed time

$
0
0
Can you give me maybe a short example how to use NotifyingSampleProvider with AudioFileReader?

New Post: Stop one song and start another - Both songs play at once

$
0
0
I'm using WaveOut and AudioFileReader to play MP3 files.

I can start playing a song using the following code, attached to my "Play" button.
void StartPlaying()
{
            _audioFileReader = new AudioFileReader(GetRandomSongFilename());
            _waveOutDevice.Init(_audioFileReader);
            _waveOutDevice.Play();
}
This works fine.

I added a "Stop" button which runs the following code:
void StopPlaying()
{
            _waveOutDevice.Stop();
}
This works fine too. The song stops playing.

I can now click my "Play" button again, and it chooses another song and it starts playing. So far, so good.

Next, I added a "Skip" button, which should skip to the next song. It runs the following code:
void SkipTrack()
{
            StopPlaying();
            StartPlaying();
}
When I run this code, both the current song and the new song play at the same time!

I'm not quite sure why when StopPlaying() and StartPlaying() are activated by two separate button clicks, everything works fine, and only the second song plays, but if they are activated by the same button click, then both songs play.

Interestingly enough, I tried adding a call to Application.DoEvents() in between the StopPlaying() and StartPlaying(), and that DID fix the problem. However, this is not a good solution because I am now moving this code to a non-Winforms application, so I don't have access to Application.DoEvents().

How else can I fix this?

-Joe

New Post: Stop one song and start another - Both songs play at once

$
0
0
Playback has not really stopped until you get the PlaybackStopped event. Also Init is not really designed to be called more than once. The safe solution is to create a new WaveOut for the new playback.

New Post: Volume Range of WaveOut

$
0
0
In NAudio, Volume on WaveOut goes from 0.0f (silence) to 1.0f (full volume). That gets turned into the range Freefall mentions under the hood.

New Post: Playing Audio on several soundcards

$
0
0
To play the same file on multiple soundcards the easiest way is actually still to create multiple readers and output devices. But there is no easy way to keep them in sync. It might be possible to have a bunch of BufferedWaveProviders, one for each output device, and when one runs out, we read from the single audio file reader and put the audio into all the bufferedwaveproviders.

Ideally for multi-channel audio you'd open a single audio device and play a multi-channel stream to it, rather than open more than one soundcard. I've not tried this myself with anything other than ASIO though.

New Post: Creating noise gate

$
0
0
when implementing effects, the best option is to implement the ISampleProvider interface. That way in the Read method you get floats in and emit floats out. Then all you need is to find a good noise gate algorithm - you could find one on musicdsp, or adapt the one from simple gate.

New Post: Playing Audio on several soundcards

$
0
0
Hmm, but that buffering wouldn´t sync them if I understand correctly. They would have to start perfectly parallel and process with exactly the same speed to make that work, right?

If you could figure out a sample that would be great.

New Post: Stop one song and start another - Both songs play at once

Viewing all 5831 articles
Browse latest View live


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