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

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
Ok, I figured out the Audio Level portion. I replaced a few lines in my Play method from this:

_WaveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback());
_WaveOut.Init(_WaveStream);
_WaveOut.Play();

to this:

_WaveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback());
NAudio.Wave.SampleProviders.SampleChannel Channel = new NAudio.Wave.SampleProviders.SampleChannel(_WaveStream);
NAudio.Wave.SampleProviders.MeteringSampleProvider Meter = new NAudio.Wave.SampleProviders.MeteringSampleProvider(Channel);
Meter.StreamVolume += (s, e) => Console.WriteLine("{0} - {1}", e.MaxSampleValues[0], e.MaxSampleValues[1]);
_WaveOut.Init(new NAudio.Wave.SampleProviders.SampleToWaveProvider(Meter));
_WaveOut.Play();

and it plays the stream and outputs the values. :)

<now to the volume feature>

New Post: Read Resampled WAV file to float[] with NAudio?

$
0
0
I resampled a wav file to 16 bit PCM, 8000khz, mono and would like to get some features out of it. This requires me to read the wav file to a float[].
using(WaveFileReader reader = new WaveFileReader(@"C:\Users\me\Desktop\somefile.wav")){
// read data to float[]?
}
really new to NAudio

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
I also was able to add a PreVolumeMeter event. Does anyone know which is better to use? I get that the pre is before the meter, just wondering if either had better performance or more/less overhead.

NAudio.Wave.SampleProviders.SampleChannel.PreVolumeMeter

NAudio.Wave.SampleProviders.MeteringSampleProvider.StreamVolume

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
I know I'm talking to myself, but I have my concept pretty much completed. The PreVolumeMeter seems to be a reading before any volume changes to the SampleChannel. So if you change the volume your meter reading will NOT reflect the changes.

Here is my latest working concept class if any guru's have any suggestions or if someone wants something to mess with to get them started.

--Thanks

public class TestStream : IDisposable
{
private System.Threading.Thread _StreamThread;
private System.IO.Stream _Stream = new System.IO.MemoryStream();
private NAudio.Wave.WaveStream _WaveStream;
private NAudio.Wave.WaveOut _WaveOut;
private NAudio.Wave.SampleProviders.SampleChannel _SampleChannel;
private NAudio.Wave.SampleProviders.MeteringSampleProvider _MeteringSampleProvider;
private const long _ChunkSize = 16384; // Testing (64k=65536, 32k=32768 16k=16384)

public void Dispose()
{
    if (_WaveOut.PlaybackState != NAudio.Wave.PlaybackState.Stopped)
    {
        this.Stop();
    }
    _WaveStream.Close();
    _Stream.Close();
    _WaveStream.Dispose();
    _WaveOut.Dispose();
    _Stream.Dispose();
    _StreamThread.Abort();
    _StreamThread.Join();
    System.Diagnostics.Debug.WriteLine("=> Disposed");
}

public TestStream(string UriString)
{
    _StreamThread = new System.Threading.Thread(delegate(object o)
    {
        System.Net.WebResponse response = System.Net.WebRequest.Create(UriString).GetResponse();
        using (var stream = response.GetResponseStream())
        {
            byte[] buffer = new byte[_ChunkSize];
            int read;
            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                var pos = _Stream.Position;
                _Stream.Position = _Stream.Length;
                _Stream.Write(buffer, 0, read);
                _Stream.Position = pos;
            }
        }
    });
    _StreamThread.Start();
    System.Diagnostics.Debug.WriteLine("=> Initialized");
}

public void Play()
{
    if (_Stream.Length < _ChunkSize * 5) // What increment should this be?
    {
        System.Diagnostics.Debug.WriteLine("=> Buffering");
        while (_Stream.Length < _ChunkSize * 5)
        { // Pre-buffering some data to allow NAudio to start playing
            System.Threading.Thread.Sleep(1000);
        }
    }
    _Stream.Position = 0;
    _WaveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback());
    _WaveStream = new NAudio.Wave.BlockAlignReductionStream(NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(_Stream)));
    _SampleChannel = new NAudio.Wave.SampleProviders.SampleChannel(_WaveStream);
    _SampleChannel.PreVolumeMeter += PreVolumeMeterValues;
    _MeteringSampleProvider = new NAudio.Wave.SampleProviders.MeteringSampleProvider(_SampleChannel);
    _MeteringSampleProvider.StreamVolume += PostVolumeMeterValues;
    _WaveOut.Init(new NAudio.Wave.SampleProviders.SampleToWaveProvider(_MeteringSampleProvider));
    _WaveOut.Play();
    System.Diagnostics.Debug.WriteLine("=> Playing");
}

public void Stop()
{
    _WaveOut.Stop();
    System.Diagnostics.Debug.WriteLine("=> Stopped");
}

public void SetVolume(float Volume)
{
    System.Diagnostics.Debug.WriteLine(String.Format("=> Volume Adjustment set to {0}", Volume));
    _SampleChannel.Volume = Volume;
}

private void PreVolumeMeterValues(object sender, NAudio.Wave.SampleProviders.StreamVolumeEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(String.Format("Pre-Volume: {0} <==> {1}", e.MaxSampleValues[0], e.MaxSampleValues[1]));
}

private void PostVolumeMeterValues(object sender, NAudio.Wave.SampleProviders.StreamVolumeEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(String.Format("Post-Volume: {0} <==> {1}", e.MaxSampleValues[0], e.MaxSampleValues[1]));
}
}

New Post: Read Resampled WAV file to float[] with NAudio?

$
0
0
AudioFileReader will give you the samples already converted to floats. Alternatively put a Pcm16ToSampleProvider after the reader

New Post: Supported Sounds Format

$
0
0
hi;
i took a brief look at the api , but i'm wondering what are supported audio formats for reading and writing in this library ?
thank you for the job done .

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
Glad you got something working in the end. It's called the "Pre" Volume meter, because it allows metering before the volume control. This is useful for drawing waveforms.
Also no need for NAudio.Wave.BlockAlignReductionStream and NAudio.Wave.WaveFormatConversionStream.CreatePcmStream. Mp3FileReader returns PCM already.

New Post: Supported Sounds Format


New Post: Concatenate mp3 files

$
0
0
It's because there is no ACM MP3 decoder installed. You don't really need Mp3FileReader anyway. The Mp3Frame class can be used to discover MP3 frames, and you just concatenate them all into a single file.

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
Thanks and I will update my code.

New Post: Need help reviewing code for a stream player. Can't get a few features integrated.

$
0
0
One more thing. How would I go about limiting my MemoryStream amount. It seems the longer I let my stream play the more memory it uses. Is there a way to clear the buffer after it's played or every few minutes? Without interruption?

-George

New Post: InvalidOperationException on playing some MP3 files

New Post: InvalidOperationException on playing some MP3 files

$
0
0
Thanks for these. I've seen instances where the album art can get misinterpreted as a valid mp3 header. I'm not sure how to work around this. There might be some deeper checking within the MP3 frame payload, but that would require more knowledge than NAudio currently has of the inner workings of MP3. I'll keep hold of the files in the hopes that one day I'll find a good way to deal with this issue.

New Post: Concatenate mp3 files

$
0
0
Mark, you have no idea how I appreciate your insight. I was banging my head against a wall for many many hours changing registries on the server and trying this and that to make it work. It is working great now.

New Post: MidiOut is not working

$
0
0
Sorry, I misunderstood. There is way to render midi sound out to speaker?

New Post: IWaveProvider - streaming 16Bit PCM audio

$
0
0
Is there a way to convert Big Endian formatted received bytes from network to little endian for recording as wave file?

I have to convert 512 bytes for each 16 ms interval from big endian to little endian for my recorder, and I wonder if cpu can handle this operation.

My incoming stream from network is 8Khz, 16 bit, stereo.

I am searching if NAudio has an utility for handling this kind of problem.

Thanks.

New Post: IWaveProvider - streaming 16Bit PCM audio

$
0
0
nothing built in to NAudio. I'd just swap each pair of bytes in the incoming buffer before moving on.

Source code checked in, #2339a04e76cc

$
0
0
accepting pull request for MP3 Frame Decompressor

New Post: MidiOut is not working

$
0
0
MIDI messages must be sent to a synthesizer, not to a speaker. The synthesizer is responsible for sending sound to the speaker.

New Post: Best strategy to resample IEEE 32 bit streams in Windows XP?

$
0
0
Hi there,

I am trying to resample some uncompressed WAV files that have different sample rates. All of them are IEEE 32 bit streams and I usually have to resample them from 44.1 to 48 or the other way around. ACM doesn't work and always gives me an "ACM Not Possible" error with IEEE 32 bit streams, therefore I need to use another resampler.

The requirements are:
  • Must work with Windows XP
  • Don't want to downbit to 16 bits. I'd like to maintain always the IEEE 32 bit.
  • The resample needs to have some quality with filtering if possible.
Do you know what would be the best strategy for this case? Is NAudio able to perform such operations in Windows XP or do I need to use SoX or other external programs/libs to perform this?

Thanks a lot for NAudio by the way. It is a great library! :)
Viewing all 5831 articles
Browse latest View live


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