clarkezone / audiovisualizer

A UWP audio visualization component that provides a stream analyzer and XAML visualization controls for displaying VU and spectrum meters powered by Win2D
MIT License
122 stars 26 forks source link

Error when playing mono audio file #61

Closed daltskin closed 6 years ago

daltskin commented 6 years ago

When using the VisualizationPlayer to play a mono wav (attached) file getting the following error:

Exception thrown: 'System.ArgumentException' in VisualizationPlayer.exe WinRT information: Previous data not the same size An exception of type 'System.ArgumentException' occurred in VisualizationPlayer.exe but was not handled in user code WinRT information: Previous data not the same size The parameter is incorrect.

Raised from following:

_previousSpectrum = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration); SampleAudio_0.4mb-mono.zip

tonuv commented 6 years ago

I am not able to repro this with the most recent sample app and 1.07 nuget package. This error though indicates that the spectrumData and _previousSpectrum have different dimensions. Please let me know if this still reproes on your side.

jjouppi commented 4 years ago

Hey! Thanks for everyone's work on this awesome tool.

Just wanted to report that I encountered this same error when playing mono files with a custom visualizer. I based my visualizer off the custom draw visualizer in the sample app. Received the error "Previous data not the same size" from the same line as the OP.

Also noticed that in the sample app, if I open a mono file, the Custom Draw visualizer disappears. If I subsequently attempt to open a stereo file, the sample app crashes.

It seems to me that the problem could have to do with _emptySpectrum used when spectumData is either null or the media player is paused:

var spectrumData = args.Data != null &&
                                 spectrum.Source?.PlaybackState == SourcePlaybackState.Playing ?
                                 args.Data.Spectrum.LogarithmicTransform(spectrumBarCount, 20f, 20000f) :
                                 _emptySpectrum; <==This property here

_previousSpectrum = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration);

that property is set only once and it is set with 2 channels:

SpectrumData _emptySpectrum = SpectrumData.CreateEmpty(2, spectrumBarCount,ScaleType.Linear,ScaleType.Linear,0, 20000);

Seems that the problem could be the mismatch of channel counts between the SpectrumData and the _emptySpectrum? I attempted to resolve this by setting the audio channel count property of _emptySpectrum when loading my source:

private void Playback_SourceChanged(object sender, IVisualizationSource source)
{
    spectrum.Source = _playbackSource.Source;
    audioChannelCount = (uint)spectrum.Source.ActualChannelCount;
    _emptySpectrum = SpectrumData.CreateEmpty((uint)audioChannelCount, spectrumBarCount, ScaleType.Linear, ScaleType.Linear, 0, 20000);
}

but still encountered the same error. Any thoughts as to what it could be? Right now I'm attempting to create two separate visualizers, one for mono and one for stereo audio, and see how that goes.

jjouppi commented 4 years ago

Just wanted to follow up:

Creating separate visualizers for mono or stereo content does work and should be sufficient for my solution. However, I noticed that the issue also occurs when opening multichannel audio such as these test files here: https://www2.iis.fraunhofer.de/AAC/multichannel.html

As with mono and stereo files, if you set a source that is multichannel and then attempt to set a new source with a different channel count, your receive the error "Previous data not the same size" from the line:

_previousSpectrum = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration);