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

New Post: savefile

$
0
0
markheath,

I am trying to save a file of the tone before I mix with the other files but I can seem to do it
this is what i have now

                SaveFileDialog save1 = new SaveFileDialog();
                save1.Filter = "Wave file (*.wav)|*.wav;";
                if(save1.ShowDialog() != DialogResult.OK) return;

                WaveFileWriter wavefile = new WaveFileWriter(save1.FileName, sineWaveProvider.WaveFormat);
                for(int i =0; i< sineWaveProvider.buffer1.Length; i++)
                {
                wavefile.WriteSample(sineWaveProvider.buffer1[i]); 
                }
                wavefile.Flush();
but the file empty
and so is the buffer...

I make the tone before hand in sinewaveProvider
and i can play sinewaveProvider and I can mix it, but I can seem to write in to a file
why?
I made buffer public
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAudio.Wave;
using NAudio;

namespace Isochronic_tones_generator
{
    public class SineWaveProvider32 : WaveProvider32
{
    int sample;
    double f2;
    public SineWaveProvider32()
    {
        Frequency = 1000;
        Amplitude = 0.25f; // let's not hurt our ears     
        Beat = 0;
    }
 
    public float Frequency { get; set; }
    public float Amplitude { get; set; }
    public float Beat { get; set; }
    public float[] buffer1 { get; set; } 

    public override int Read(float[] buffer, int offset, int sampleCount)
    {
        int sampleRate = WaveFormat.SampleRate;
        if (Beat == 0)
        {
            f2 = 0;
        }
        else
        {
            f2 = Frequency - Beat;
        }
        for (int n = 0; n < sampleCount; n++)
        {
            buffer[n + offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate)) + (float)(Amplitude * Math.Sin((2 * Math.PI * sample * f2) / sampleRate));
            sample++;
            if (sample >= sampleRate) sample = 0;
        }
        buffer1 = buffer;
        return sampleCount;
    }
}
}
that should work right ?

Viewing all articles
Browse latest Browse all 5831

Trending Articles



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