This project has moved and is read-only. For the latest updates, please go here.

adding effect to MP3 file

Jun 20, 2014 at 3:35 PM
I have an EffectStream class that takes in a WaveStream and then multiply the values in the file by a giving number... so sample = sample * 0.5 ;

So this works for wave files. however not for mp3 file. When a file is upload it , I check and see if the file is a wave file or a MP3 file. if it is an MP3 file I convert it into a wave stream and then I do the effect.

however when I play it back, I get white noise out one earphone and the song out the other earphone. Again this process works for a wave file. so I think something might be wrong with the wave conversion.

I checked and the sampling rate, bits per sample, and the channel are set to the right values:
44100, 16, 2
so I am not sure where to go from here.
below is my code :
this is my read function from the effect class.
the EffectStream class inherit from WaveStream class
 public override int Read(byte[] buffer, int offset, int count)
            Console.WriteLine("DirectSoundOut requested {0} bytes", count);

            int read = SourceStream.Read(buffer, offset, count);

            for (int i = 0; i < read / 4; i++)
                float sample = BitConverter.ToSingle(buffer, i * 4);
                sample = sample * number;

                byte[] bytes = BitConverter.GetBytes(sample);
                buffer[i * 4 + 0] = bytes[0];
                buffer[i * 4 + 1] = bytes[1];
                buffer[i * 4 + 2] = bytes[2];
                buffer[i * 4 + 3] = bytes[3];

            return read;
here is the main
 else if (Stemp == "mp3")
               pcm = WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(Filelist.Text));
               effect = new EffectStream(pcm);
                stream = new BlockAlignReductionStream(effect);  
                effect.number = (float)Convert.ToDouble(textBox1.Text);
                if (waveout == null)
                    waveout = new WaveOut();
                    waveout.PlaybackStopped += onPlaybackStopped;
                playToolStripMenuItem.Enabled = false;
                stopToolStripMenuItem.Enabled = true;
                puaseToolStripMenuItem.Enabled = true;
thanks for the help
Jun 29, 2014 at 11:40 PM
well if it's 16 bit audio, don't use BitConverter.ToSingle - its a Short (Int16) not a float