Problem mit CSCore.Visualisierung

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von sothere.

    Problem mit CSCore.Visualisierung

    Hi
    Ich habe ein Problem mit CSCore und der Visualisierungsfunktion.
    Ich habe den C# Quelltext soweit umgesetzt, aber mein Problem ist, das in der Pictruebox nichts ausgegeben wird.
    Das liegt daran, das ich diesen Code:

    Quellcode

    1. var notificationSource = new CSCore.Streams.SingleBlockNotificationStream(source);
    2. notificationSource.SingleBlockRead += (s, a) =>
    3. {
    4. spectrumProvider.Add(a.Left, a.Right);
    5. };
    6. source = notificationSource.ToWaveSource(16);


    nicht konvertiert bekomme. Ich habe es schon mit einem Online-Tool versucht, aber da kam auch nur eine nicht funktionierende Funktion raus:

    VB.NET-Quellcode

    1. Dim notificationSource = New CSCore.Streams.SingleBlockNotificationStream(source)
    2. notificationSource.SingleBlockRead += Function(s, a)
    3. spectrumProvider.Add(a.Left, a.Right)
    4. End Function
    5. source = notificationSource.ToWaveSource(16)


    VS2013 sagt mir dann folgendes:
    "Public Event SingleBlockRead(sender As Object, e As CSCore.Streams.SingleBlockReadEventArgs)" ist ein Ereignis und kann nicht direkt aufgerufen werden. Verwenden Sie eine RaiseEvent-Anweisung, um ein Ereignis aufzurufen.
    Wie kann ich das beheben?
    Liebe Grüße
    sothere
    Event += Handler ist in VB AddHandler Event, AddressOf Handler
    Also:

    VB.NET-Quellcode

    1. AddHandler notificationSource.SingleBlockRead, AddressOf addSpectrum
    2. Public Sub addSpectrum(left As Float(), right As Float())
    3. spectrumProvider.Add(left, right)
    4. End Sub


    Wenn die notificationSource in der Klasse bekannt ist:

    VB.NET-Quellcode

    1. Public Sub addSpectrum(left As Float(), right As Float()) Handles notificationSource.SingleBlockRead
    2. spectrumProvider.Add(left, right)
    3. End Sub
    das Problem ist aber, das ich das nicht in ein extra Sub ausgliedern kann:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports CSCore
    2. Imports CSCore.CoreAudioAPI
    3. Imports CSCore.SoundOut
    4. Imports CSCore.Codecs
    5. Imports CSCore.Streams
    6. Imports CSCore.Visualization.Winforms
    7. Imports CSCore.Visualization
    8. Public Class Form2
    9. Private _soundOut As ISoundOut
    10. Private _spectrum As LineSpectrum
    11. Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    12. Dim ofd As New OpenFileDialog()
    13. ofd.Filter = CodecFactory.SupportedFilesFilterEN
    14. If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    15. [Stop]()
    16. Dim fftSize__1 As FFTSize = FFTSize.FFT4096
    17. Dim source As IWaveSource = CodecFactory.Instance.GetCodec(ofd.FileName)
    18. Dim spectrumProvider = New BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize__1)
    19. _spectrum = New LineSpectrum(fftSize__1)
    20. _spectrum.SpectrumProvider = spectrumProvider
    21. _spectrum.UseAverage = True
    22. _spectrum.BarCount = 50
    23. _spectrum.BarSpacing = 2
    24. _spectrum.IsXLogScale = True
    25. _spectrum.ScalingStrategy = ScalingStrategy.Sqrt
    26. Dim notificationSource = New CSCore.Streams.SingleBlockNotificationStream(source)
    27. 'Hier muss die besagte änderung erfolgen
    28. source = notificationSource.ToWaveSource(16)
    29. source = notificationSource.ToWaveSource(16)
    30. _soundOut = New WasapiOut()
    31. _soundOut.Initialize(New LoopStream(source))
    32. _soundOut.Play()
    33. Timer1.Enabled = True
    34. PropertyGrid1.SelectedObject = _spectrum
    35. End If
    36. End Sub
    37. Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    38. Dim image = PictureBox1.Image
    39. PictureBox1.Image = _spectrum.CreateSpectrumLine(PictureBox1.Size, Color.Green, Color.Red, Color.Black, True)
    40. If image IsNot Nothing Then
    41. image.Dispose()
    42. End If
    43. End Sub
    44. Private Sub [Stop]()
    45. Timer1.Stop()
    46. If _soundOut IsNot Nothing Then
    47. Dim source = _soundOut.WaveSource
    48. _soundOut.[Stop]()
    49. _soundOut.Dispose()
    50. source.Dispose()
    51. _soundOut = Nothing
    52. End If
    53. End Sub
    54. End Class



    Wie kann ich das sonst lösen?
    Liebe Grüße
    sothere
    Hier, ich habs dir mal per Hand übersetzt:

    VB.NET-Quellcode

    1. Dim notificationSource = New SingleBlockNotificationStream(source)
    2. AddHandler notificationSource.SingleBlockRead, Sub(s, a) spectrumProvider.Add(a.Left, a.Right)
    3. source = notificationSource.ToWaveSource(16)
    Vielen Dank für deine Hilfe. Jetzt sehe ich kurz ein Bild, eh das Programm abstürtzt:

    Ein Ausnahmefehler des Typs "System.NullReferenceException" ist in CSCore.dll aufgetreten.

    Zusätzliche Informationen: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.


    Der komplette Code:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports CSCore
    2. Imports CSCore.CoreAudioAPI
    3. Imports CSCore.SoundOut
    4. Imports CSCore.Codecs
    5. Imports CSCore.Streams
    6. Imports CSCore.Visualization.Winforms
    7. Imports CSCore.Visualization
    8. Public Class Form2
    9. Private _soundOut As ISoundOut
    10. Private _spectrum As LineSpectrum
    11. Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    12. Dim ofd As New OpenFileDialog()
    13. ofd.Filter = CodecFactory.SupportedFilesFilterEN
    14. If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    15. [Stop]()
    16. Dim fftSize__1 As FFTSize = FFTSize.FFT4096
    17. Dim source As IWaveSource = CodecFactory.Instance.GetCodec(ofd.FileName)
    18. Dim spectrumProvider = New BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize__1)
    19. _spectrum = New LineSpectrum(fftSize__1)
    20. _spectrum.SpectrumProvider = spectrumProvider
    21. _spectrum.UseAverage = True
    22. _spectrum.BarCount = 50
    23. _spectrum.BarSpacing = 2
    24. _spectrum.IsXLogScale = True
    25. _spectrum.ScalingStrategy = ScalingStrategy.Sqrt
    26. Dim notificationSource = New SingleBlockNotificationStream(source)
    27. AddHandler notificationSource.SingleBlockRead, Sub(s, a) spectrumProvider.Add(a.Left, a.Right)
    28. source = notificationSource.ToWaveSource(16)
    29. source = notificationSource.ToWaveSource(16)
    30. _soundOut = New WasapiOut()
    31. _soundOut.Initialize(New LoopStream(source))
    32. _soundOut.Play()
    33. Timer1.Enabled = True
    34. PropertyGrid1.SelectedObject = _spectrum
    35. End If
    36. End Sub
    37. Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    38. Dim image = PictureBox1.Image
    39. PictureBox1.Image = _spectrum.CreateSpectrumLine(PictureBox1.Size, Color.Green, Color.Red, Color.Black, True)
    40. If image IsNot Nothing Then
    41. image.Dispose()
    42. End If
    43. End Sub
    44. Private Sub [Stop]()
    45. Timer1.Stop()
    46. If _soundOut IsNot Nothing Then
    47. Dim source = _soundOut.WaveSource
    48. _soundOut.[Stop]()
    49. _soundOut.Dispose()
    50. source.Dispose()
    51. _soundOut = Nothing
    52. End If
    53. End Sub
    54. End Class



    Hat jemand da eine Idee?

    PS: Ich finde es schade, das es für CSCore keine Doku gibt. Die Libary ist echt mächtig, aber man kann sie halt nicht ausnutzen.
    Liebe Grüße
    sothere
    ah okay, danke :)
    Mal noch eine ganz andere Frage:
    Ich wollte den Code gerade in ein neues Projekt integieren, als ich feststellen musste, das ich plötzlich CSCore.Visualization.Winforms nicht mehr importieren konnte, sondern nurnoch CSCore.Visualization.WPF . Damit funktioniert das ganze ja logischer weise nicht mehr. Hat irgendwer eine Idee, woran das liegt?
    Liebe Grüße
    sothere