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

New Post: WaveViewer loses image of waveform

$
0
0

Hi, this is 5th day that I can't solve this problem. Firstly I thought it was something with C# and .NET But know I lost all my hopes and will to live ;)

I made a class - AudioManager which has ability to play and record sound. It looks something like this:

private DirectSoundOut output = null;
private WaveIn input = null;
private WaveFileWriter waveWriter = null;
private WaveFileReader waveReader = null;


public void LoadFile(string fileName)
{
      CloseAll(); //just disposes all streams and NAudio objects, like output
      waveReader = new WaveFileReader(fileName);
 
      output = new DirectSoundOut();
      output.Init(new WaveChannel32(waveReader));
}


//plays loaded file
public void Play()
{
      if (_state == State.MONITORING) StopRecord();
      if (output == null) return;
      if (output.PlaybackState != PlaybackState.Playing)
      {
          output.Play();
          _state = State.PLAYING;
      }
}


//stops playing file
public void Stop()
{
      if (output == null) return;
      if (output.PlaybackState != PlaybackState.Stopped)
      {
          output.Stop();
          _state = State.STOPPED;
      }
}


public WaveFileReader GetWaveReader()
{
      return waveReader;
}

 

Recording is fine, so I don't show it here. Anyway, after recording a file, I do some cutting in this file - simply I cut part of the wave file. This works fine also. Then I load new(cutted) file into my AudioManager, and want to show new waveform:

JuhasWaveViewer wv = GetWaveViewer(clickedIndex); //JuhasWaveViewer is standard NAudio.WaveViewer with some new features like colors and cutting

string filename = GetCheckedFileName(); //this filename resides in TAG property of WaveViewer
wv.CutSelection(filename); //cuts some part of file and saves the new file with the same name

am.LoadFile(filename); //loads this new file to my AudioManager

//now I want to draw new waveform. _ws is my private WaveStream
wv.WaveStream = null;
_ws = new RawSourceWaveStream(am.GetWaveReader(), am.GetWaveReader().WaveFormat);
wv.WaveStream = _ws;

 

(I use _ws just for some debugging, normally I would do just: wv.WaveStream = new RawSourceWaveStream....)
Until now everything works and WaveViewer shows new waveform. I can resize my WaveViewer and everything works fine. But, then I want to play this new file. So I use am.Play() method. It plays - I can hear that this is the cutted file. But now, when I want to resize my waveStream or do anything else with it, it loses waveform and shows just white field with red x-like cross. I was checking the memory and found that _ws is in different place in memory than it was on the start, but wv.WaveStream still points to _ws, so they are still connected. So what is the issue? What am I doing wrong?

I even tried to call Invalidate on waveViewer, but it doesn't work. Please help me


Viewing all articles
Browse latest Browse all 5831

Trending Articles



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