processing / processing-sound

Audio library for Processing built with JSyn
https://processing.org/reference/libraries/sound/
GNU Lesser General Public License v2.1
149 stars 50 forks source link

Analyzer stops working when input AudioSample/SoundFile playback stops/runs out #95

Closed bigboss97 closed 8 months ago

bigboss97 commented 11 months ago

I've written many sketches using v2.3.1. I always have the issue with incorrect sample rate in MP3 which causes slower playback. I want to see whether this is still in v2.4. Today I downloaded v2.4 and tried on my old sketch. Everything works fine, i.e. progress bar, FFT etc. but no sound. I tried to use amp(1), still no luck. What could be the reason?

I'm running Processing 3.5.4 on Windows 11 Home.

kevinstadler commented 11 months ago

Hello, thanks for reporting. Could you please first try adding Sound.list(); to your sketch's setup() and make sure that you have selected the correct output device. If that doesn't fix it, could you please call Sound.list(); as well as Sound.status(); from the very end of your sketch's setup() and post the sketch's output here (as well as the full code of your sketch). Thanks!

bigboss97 commented 11 months ago

Hello, thanks for reporting. Could you please first try adding Sound.list();

Sound.list() got stuck: Sound library: JavaSound device listing

id | Input device name             | inputs

NoSuchMethodError: java.lang.String.repeat(I)Ljava/lang/String; NoSuchMethodError: java.lang.String.repeat(I)Ljava/lang/String; NoSuchMethodError: java.lang.String.repeat(I)Ljava/lang/String; NoSuchMethodError: java.lang.String.repeat(I)Ljava/lang/String;

kevinstadler commented 11 months ago

Aaaah I see. The simplest solution would probably be for you to upgrade your Processing installation to version 4. But I will make sure to add a fix which makes v2.4 of the library backwards-compatible with Processing 3 installations in the next few hours.

bigboss97 commented 11 months ago

Thanks for your time.

I just ran my sketch on Processing 4.1.1 and it works fine with library v2.3. Then I changed it to v2.4, no sound, same as on P3:

Sound library: JavaSound device listing

    id | Input device name             | inputs
   ----+-------------------------------+--------
 I   4 | Primary Sound Capture Driver  |    2
     5 | Microphone (Realtek(R) Audio) |    2

    id | Output device name            | outputs
   ----+-------------------------------+--------
 O   2 | Primary Sound Driver          |    2
     3 | Speakers (Realtek(R) Audio)   |    2

Sound library: synthesis has been running for 1.40 seconds, generated 61696 frames (framerate 44100)
  audio devices used by JavaSound:
    input from 'Primary Sound Capture Driver': 2 channels, latency 100ms
    output on 'Primary Sound Driver': 2 channels, latency 80ms

  nodes in synthesizer network: 0
  decoded audio samples held in cache: 0 (0 frames total)
  CPU usage: 1%

A side note, it would be nice to have the library version in the status information.

So I though I might have to switch output ID 3 and I did:

Sound.outputDevice(3);
Sound library: JavaSound device listing

    id | Input device name             | inputs
   ----+-------------------------------+--------
 I   4 | Primary Sound Capture Driver  |    2
     5 | Microphone (Realtek(R) Audio) |    2

    id | Output device name            | outputs
   ----+-------------------------------+--------
     2 | Primary Sound Driver          |    2
 O   3 | Speakers (Realtek(R) Audio)   |    2

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
    at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:484)
    at java.desktop/com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:115)
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.start(JavaSoundAudioDevice.java:273)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(SynthesisEngine.java:309)
java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.TargetDataLine.read(byte[], int, int)" because "this.line" is null
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(JavaSoundAudioDevice.java:300)
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(JavaSoundAudioDevice.java:291)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(SynthesisEngine.java:330)
java.lang.RuntimeException: AudioInput stop attempted when no line created.
    at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.stop(JavaSoundAudioDevice.java:318)
    at com.jsyn.engine.SynthesisEngine$EngineThread.run(SynthesisEngine.java:357)
kevinstadler commented 11 months ago

That's super helpful, thank you very much! Could you please post your full sketch code? I think it should also be possible to upload the .pde file as an attachment to a Github comment.

Another fix you could try right now is to call MultiChannel.usePortAudio(); at the very beginning of your setup(), that should change the list of output devices that you can try out.

Also could I ask what sound card/hardware you are using?

Best

bigboss97 commented 11 months ago

testSoundLib.zip

I tried to write a simple sketch. But that worked. Now I'm attaching a stripped down version of my program which plays no sound with lib2.4.

bigboss97 commented 11 months ago

Another fix you could try right now is to call MultiChannel.usePortAudio(); at the very beginning of your setup(), that should change the list of output devices that you can try out.

MultiChannel is not recognized. Do I have to import something?

kevinstadler commented 11 months ago

Are you sure you have library version 2.4 installed at the moment? MultiChannel should be available as long as you are using import processing.sound.*;, which it looks like you do.

Thanks for posting your sketch by the way, it's extremely helpful for us to figure out any troubles that arise between 2.3 and 2.4, especially for complex sketches such as this!

bigboss97 commented 11 months ago

Sorry, I didn't know it's from Sound library. I thought it's native Processing. Therefor I tried that on P3 and P4. Anyway, this is MultiChannel.usePortAudio() from P3:

RuntimeException: PortAudio is not supported on this operating system/architecture
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

and this is from P4:

before paHostApiInitializers[0].
after paHostApiInitializers[0].
before paHostApiInitializers[1].
after paHostApiInitializers[1].
before paHostApiInitializers[2].
WASAPI: device idx: 00
WASAPI: ---------------
WASAPI:0| name[Speakers (Realtek(R) Audio)]
WASAPI:0| form-factor[1]
WASAPI: getting Windows version with RtlGetVersion()
WASAPI: Windows version = 5
WASAPI: IAudioClient version = 3
WASAPI:0| def.SR[48000] max.CH[2] latency{hi[0.010000] lo[0.003000]}
WASAPI: device idx: 01
WASAPI: ---------------
WASAPI:1| name[Microphone (Realtek(R) Audio)]
WASAPI:1| form-factor[4]
WASAPI:1| def.SR[48000] max.CH[2] latency{hi[0.010000] lo[0.003000]}
WASAPI: device list ok - found 2 devices
WASAPI: initialized ok
after paHostApiInitializers[2].
before paHostApiInitializers[3].
Setup called
Enum called
noError = 0
Device 0 has capture alias
Enum called
noError = 0
Enum called
noError = 1
Device 2 has render alias
Enum called
noError = 0
Enum called
noError = 0
Enum called
noError = 0
Device 5 has capture alias
Enum called
noError = 1
Device 6 has render alias
Device 6 has capture alias
Enum called
noError = 0
Enum called
Interfaces found: 4
Device 0 has capture alias
Device 0 has realtime alias
Interface 0, Name: R
FilterNew: Creating filter 'Realtek HD Audio Mic input'
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=2, nodes=1
  Connection: 0 - FromNode=4294967295,FromPin=1 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=4294967295,ToPin=0
  Node: 0 - {4D837FE0-C555-11D0-8A2B-00A0C9255AC1}
PinNew: Creating pin 0:
PinNew: Checking 1 no of dataranges...
PinNew: DR major format 73647561
PinNew: MaxChannel: 2
PinNew: Format PCM 16 bit supported
PinNew: Default sample rate = 44100 Hz
Failed PinQueryNotificationSupport
PinNew: Finding topology pin...
FindStartConnectionFrom: Startpin 0, Checking 2 connections...
FindStartConnectionFrom: returning 00000254AAFEB7D8
GetConnectedPin: count=1, forward=0, muxPosition=-1
GetConnectionFrom: Checking 2 connections... (pTo = 00000254AAFEB7D8)
GetConnectionFrom: Returning 00000254AAFEB7C8
PinNew: Getting physical connection...
PinNew: Physical connection found!
PinNew: Creating topology filter '\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0269&SUBSYS_15588500&REV_1002#4&31a59183&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\RtMicInTopo'
FilterNew: Creating filter ''
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=4, nodes=3
  Connection: 0 - FromNode=4294967295,FromPin=1 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=2,ToPin=1
  Connection: 2 - FromNode=2,FromPin=0 -> ToNode=1,ToPin=1
  Connection: 3 - FromNode=1,FromPin=0 -> ToNode=4294967295,ToPin=0
  Node: 0 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 1 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 2 - {02B223C0-C557-11D0-8A2B-00A0C9255AC1}
PinNew: Opening topology filter...PinNew: Checking for input endpoint pin id (0)...
FindStartConnectionFrom: Startpin 0, Checking 4 connections...
FindStartConnectionFrom: returning 00000254AAB830B8
GetConnectedPin: count=3, forward=0, muxPosition=0
GetConnectionFrom: Checking 4 connections... (pTo = 00000254AAB830B8)
GetConnectionFrom: Returning 00000254AAB830A8
GetConnectedPin: count=3, forward=0, muxPosition=0
GetConnectionFrom: Checking 4 connections... (pTo = 00000254AAB830A8)
GetConnectionFrom: Returning 00000254AAB83098
GetConnectedPin: count=3, forward=0, muxPosition=0
GetConnectionFrom: Checking 4 connections... (pTo = 00000254AAB83098)
GetConnectionFrom: Returning 00000254AAB83088
PinNew: Found endpoint pin id 1
PinNew: Input friendly name 'Microphone'
PinNew: Releasing topology filter...
Pin created successfully
PinNew: Creating pin 1:
PinNew: Not source/sink
PinNew: Error -9996
Filter (WaveRT) created with 1 valid pins (total I/Os: 1)
Device 2 has render alias
Device 2 has realtime alias
Interface 2, Name: R
FilterNew: Creating filter 'Realtek HD Audio output'
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=2, nodes=1
  Connection: 0 - FromNode=4294967295,FromPin=0 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=4294967295,ToPin=1
  Node: 0 - {507AE360-C554-11D0-8A2B-00A0C9255AC1}
PinNew: Creating pin 0:
PinNew: Checking 1 no of dataranges...
PinNew: DR major format 73647561
PinNew: MaxChannel: 2
PinNew: Format PCM 16 bit supported
PinNew: Format PCM 24 bit supported
PinNew: Format PCM 32 bit supported
PinNew: Default sample rate = 44100 Hz
Failed PinQueryNotificationSupport
PinNew: Finding topology pin...
FindStartConnectionTo: Startpin 0, Checking 2 connections...
FindStartConnectionTo: returning 00000254AAFEBA98
GetConnectedPin: count=1, forward=1, muxPosition=-1
GetConnectionTo: Checking 2 connections... (pFrom = 00000254AAFEBA98)GetConnectionTo: Returning 00000254AAFEBAA8
PinNew: Getting physical connection...
PinNew: Physical connection found!
PinNew: Creating topology filter '\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0269&SUBSYS_15588500&REV_1002#4&31a59183&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\SingleLineOutTopo'
FilterNew: Creating filter ''
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=7, nodes=5
  Connection: 0 - FromNode=4294967295,FromPin=0 -> ToNode=2,ToPin=1
  Connection: 1 - FromNode=2,FromPin=0 -> ToNode=0,ToPin=1
  Connection: 2 - FromNode=0,FromPin=0 -> ToNode=1,ToPin=1
  Connection: 3 - FromNode=1,FromPin=0 -> ToNode=4294967295,ToPin=1
  Connection: 4 - FromNode=4294967295,FromPin=2 -> ToNode=4,ToPin=1
  Connection: 5 - FromNode=4,FromPin=0 -> ToNode=3,ToPin=1
  Connection: 6 - FromNode=3,FromPin=0 -> ToNode=2,ToPin=2
  Node: 0 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 1 - {02B223C0-C557-11D0-8A2B-00A0C9255AC1}
  Node: 2 - {DA441A60-C556-11D0-8A2B-00A0C9255AC1}
  Node: 3 - {02B223C0-C557-11D0-8A2B-00A0C9255AC1}
  Node: 4 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
PinNew: Opening topology filter...PinNew: Checking for output endpoint pin id...
FindStartConnectionTo: Startpin 0, Checking 7 connections...
FindStartConnectionTo: returning 00000254AAAEEF78
GetConnectedPin: count=5, forward=1, muxPosition=-1
GetConnectionTo: Checking 7 connections... (pFrom = 00000254AAAEEF78)GetConnectionTo: Returning 00000254AAAEEF88
GetConnectedPin: count=5, forward=1, muxPosition=-1
GetConnectionTo: Checking 7 connections... (pFrom = 00000254AAAEEF88)GetConnectionTo: Returning 00000254AAAEEF98
GetConnectedPin: count=5, forward=1, muxPosition=-1
GetConnectionTo: Checking 7 connections... (pFrom = 00000254AAAEEF98)GetConnectionTo: Returning 00000254AAAEEFA8
PinNew: Found endpoint pin id 1
GetNameFromCategory: USB GUID 0301 -> 'Speakers'
PinNew: Pin name 'Speakers'
PinNew: Releasing topology filter...
Pin created successfully
PinNew: Creating pin 1:
PinNew: Not source/sink
PinNew: Error -9996
Filter (WaveRT) created with 1 valid pins (total I/Os: 1)
Device 5 has capture alias
Device 5 has realtime alias
Interface 5, Name: R
FilterNew: Creating filter 'Realtek HD Audio Stereo input'
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=2, nodes=1
  Connection: 0 - FromNode=4294967295,FromPin=1 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=4294967295,ToPin=0
  Node: 0 - {4D837FE0-C555-11D0-8A2B-00A0C9255AC1}
PinNew: Creating pin 0:
PinNew: Checking 1 no of dataranges...
PinNew: DR major format 73647561
PinNew: MaxChannel: 2
PinNew: Format PCM 16 bit supported
PinNew: Default sample rate = 48000 Hz
Failed PinQueryNotificationSupport
PinNew: Finding topology pin...
FindStartConnectionFrom: Startpin 0, Checking 2 connections...
FindStartConnectionFrom: returning 00000254AADA67F8
GetConnectedPin: count=1, forward=0, muxPosition=-1
GetConnectionFrom: Checking 2 connections... (pTo = 00000254AADA67F8)
GetConnectionFrom: Returning 00000254AADA67E8
PinNew: Getting physical connection...
PinNew: Physical connection found!
PinNew: Creating topology filter '\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0269&SUBSYS_15588500&REV_1002#4&31a59183&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\RtStereoMixTopo'
FilterNew: Creating filter ''
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=3, nodes=2
  Connection: 0 - FromNode=4294967295,FromPin=1 -> ToNode=1,ToPin=1
  Connection: 1 - FromNode=1,FromPin=0 -> ToNode=0,ToPin=1
  Connection: 2 - FromNode=0,FromPin=0 -> ToNode=4294967295,ToPin=0
  Node: 0 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 1 - {02B223C0-C557-11D0-8A2B-00A0C9255AC1}
PinNew: Opening topology filter...PinNew: Checking for input endpoint pin id (0)...
FindStartConnectionFrom: Startpin 0, Checking 3 connections...
FindStartConnectionFrom: returning 00000254AAFEA398
GetConnectedPin: count=2, forward=0, muxPosition=0
GetConnectionFrom: Checking 3 connections... (pTo = 00000254AAFEA398)
GetConnectionFrom: Returning 00000254AAFEA388
GetConnectedPin: count=2, forward=0, muxPosition=0
GetConnectionFrom: Checking 3 connections... (pTo = 00000254AAFEA388)
GetConnectionFrom: Returning 00000254AAFEA378
PinNew: Found endpoint pin id 1
PinNew: Input friendly name 'Stereo Mix'
PinNew: Releasing topology filter...
Pin created successfully
PinNew: Creating pin 1:
PinNew: Not source/sink
PinNew: Error -9996
Filter (WaveRT) created with 1 valid pins (total I/Os: 1)
Device 6 has render alias
Device 6 has capture alias
Interface 6, Name: V
FilterNew: Creating filter 'VB-Audio Point'
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=5, nodes=3
  Connection: 0 - FromNode=4294967295,FromPin=1 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=4294967295,ToPin=0
  Connection: 2 - FromNode=4294967295,FromPin=2 -> ToNode=2,ToPin=1
  Connection: 3 - FromNode=2,FromPin=0 -> ToNode=1,ToPin=1
  Connection: 4 - FromNode=1,FromPin=0 -> ToNode=4294967295,ToPin=3
  Node: 0 - {4D837FE0-C555-11D0-8A2B-00A0C9255AC1}
  Node: 1 - {507AE360-C554-11D0-8A2B-00A0C9255AC1}
  Node: 2 - {9DB7B9E0-C555-11D0-8A2B-00A0C9255AC1}
PinNew: Creating pin 0:
PinNew: Checking 1 no of dataranges...
PinNew: DR major format 73647561
PinNew: MaxChannel: 8
PinNew: Format PCM 8 bit supported
PinNew: Format PCM 16 bit supported
PinNew: Format PCM 24 bit supported
PinNew: Default sample rate = 44100 Hz
PinNew: Finding topology pin...
FindStartConnectionFrom: Startpin 0, Checking 5 connections...
FindStartConnectionFrom: returning 00000254AAEAF7E8
GetConnectedPin: count=3, forward=0, muxPosition=-1
GetConnectionFrom: Checking 5 connections... (pTo = 00000254AAEAF7E8)
GetConnectionFrom: Returning 00000254AAEAF7D8
PinNew: Getting physical connection...
PinNew: Physical connection found!
PinNew: Creating topology filter '\\?\ROOT#MEDIA#0000#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\Topology'
FilterNew: Creating filter ''
FilterNew: Opening filter...
DumpConnectionsAndNodes: connections=10, nodes=8
  Connection: 0 - FromNode=4294967295,FromPin=0 -> ToNode=0,ToPin=1
  Connection: 1 - FromNode=0,FromPin=0 -> ToNode=1,ToPin=1
  Connection: 2 - FromNode=1,FromPin=0 -> ToNode=3,ToPin=1
  Connection: 3 - FromNode=4294967295,FromPin=1 -> ToNode=2,ToPin=1
  Connection: 4 - FromNode=2,FromPin=0 -> ToNode=6,ToPin=1
  Connection: 5 - FromNode=3,FromPin=0 -> ToNode=4,ToPin=1
  Connection: 6 - FromNode=4,FromPin=0 -> ToNode=4294967295,ToPin=2
  Connection: 7 - FromNode=6,FromPin=0 -> ToNode=7,ToPin=1
  Connection: 8 - FromNode=7,FromPin=0 -> ToNode=4294967295,ToPin=3
  Connection: 9 - FromNode=5,FromPin=0 -> ToNode=4294967295,ToPin=3
  Node: 0 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 1 - {02B223C0-C557-11D0-8A2B-00A0C9255AC1}
  Node: 2 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 3 - {DA441A60-C556-11D0-8A2B-00A0C9255AC1}
  Node: 4 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
  Node: 5 - {2CEAF780-C556-11D0-8A2B-00A0C9255AC1}
  Node: 6 - {DA441A60-C556-11D0-8A2B-00A0C9255AC1}
  Node: 7 - {3A5ACC00-C557-11D0-8A2B-00A0C9255AC1}
PinNew: Opening topology filter...PinNew: Checking for input endpoint pin id (0)...
FindStartConnectionFrom: Startpin 3, Checking 10 connections...
FindStartConnectionFrom: returning 00000254AABCEC68
GetConnectedPin: count=8, forward=0, muxPosition=0
GetConnectionFrom: Checking 10 connections... (pTo = 00000254AABCEC68)
GetConnectionFrom: Returning 00000254AABCEC58
GetConnectedPin: count=8, forward=0, muxPosition=0
GetConnectionFrom: Checking 10 connections... (pTo = 00000254AABCEC58)
GetConnectionFrom: Returning 00000254AABCEC28
GetConnectedPin: count=8, forward=0, muxPosition=0
GetConnectionFrom: Checking 10 connections... (pTo = 00000254AABCEC28)
GetConnectionFrom: Returning 00000254AABCEC18
PinNew: Found endpoint pin id 1
PinNew: Input friendly name 'CABLE Output'
PinNew: Releasing topology filter...
Pin created successfully
PinNew: Creating pin 1:
PinNew: Not source/sink
PinNew: Error -9996
PinNew: Creating pin 2:
PinNew: Checking 1 no of dataranges...
PinNew: DR major format 73647561
PinNew: MaxChannel: 8
PinNew: Format PCM 8 bit supported
PinNew: Format PCM 16 bit supported
PinNew: Format PCM 24 bit supported
PinNew: Default sample rate = 44100 Hz
PinNew: Finding topology pin...
FindStartConnectionTo: Startpin 2, Checking 5 connections...
FindStartConnectionTo: returning 00000254AAEAF7F8
GetConnectedPin: count=3, forward=1, muxPosition=-1
GetConnectionTo: Checking 5 connections... (pFrom = 00000254AAEAF7F8)GetConnectionTo: Returning 00000254AAEAF808
GetConnectedPin: count=3, forward=1, muxPosition=-1
GetConnectionTo: Checking 5 connections... (pFrom = 00000254AAEAF808)GetConnectionTo: Returning 00000254AAEAF818
PinNew: Getting physical connection...
PinNew: Physical connection found!
PinNew: Opening topology filter...PinNew: Checking for output endpoint pin id...
FindStartConnectionTo: Startpin 0, Checking 10 connections...
FindStartConnectionTo: returning 00000254AABCEBE8
GetConnectedPin: count=8, forward=1, muxPosition=-1
GetConnectionTo: Checking 10 connections... (pFrom = 00000254AABCEBE8)GetConnectionTo: Returning 00000254AABCEBF8
GetConnectedPin: count=8, forward=1, muxPosition=-1
GetConnectionTo: Checking 10 connections... (pFrom = 00000254AABCEBF8)GetConnectionTo: Returning 00000254AABCEC08
GetConnectedPin: count=8, forward=1, muxPosition=-1
GetConnectionTo: Checking 10 connections... (pFrom = 00000254AABCEC08)GetConnectionTo: Returning 00000254AABCEC38
GetConnectedPin: count=8, forward=1, muxPosition=-1
GetConnectionTo: Checking 10 connections... (pFrom = 00000254AABCEC38)GetConnectionTo: Returning 00000254AABCEC48
PinNew: Found endpoint pin id 2
GetNameFromCategory: USB GUID 0301 -> 'Speakers'
PinNew: Pin name 'Speakers'
PinNew: Releasing topology filter...
Pin created successfully
PinNew: Creating pin 3:
PinNew: Not source/sink
PinNew: Error -9996
Filter (WaveCyclic) created with 2 valid pins (total I/Os: 2)
after paHostApiInitializers[3].
Pa_StartStream: waveInStart returned = 0x0.
kevinstadler commented 11 months ago

@bigboss97 and do you still not get any audio when you run your sketch on Processing4 with MultiChannel.usePortAudio() at the very top of your setup()?

bigboss97 commented 11 months ago

@bigboss97 and do you still not get any audio when you run your sketch on Processing4 with MultiChannel.usePortAudio() at the very top of your setup()?

Correct, still silent.

kevinstadler commented 10 months ago

I'm still trying to understand your testSoundLib sketch, it's very complex... What sound generators should the audio output be coming from, is it just the microphone? I wonder if it's just that the wrong input channel is selected, which would require adjusting the input index in AudioSource.pde:

 AudioIn newAudioIn() {
  return new AudioIn(this, 0);
}
bigboss97 commented 10 months ago

Finally, I located the cause of the problem. As soon as I removed fft.input then there's sound:

Screenshot - 24-01-01 15 59 09

kevinstadler commented 10 months ago

Hmmm that's strange, but good to know. What type of object is auSource.music at the moment that fft.input() is called?

bigboss97 commented 10 months ago

You can try following piece of code. That works on P4 with lib2.3, but no sound with lib2.4:


import processing.sound.*;
SoundFile  music;
FFT  fft;

void setup (){
  music= new SoundFile( this, dataPath("cheering.mp3"));
  fft = new FFT(this, 64);
  fft.input( music);
  music.play();
}

void draw() {
}
bigboss97 commented 10 months ago

Any update?

bigboss97 commented 10 months ago

Have you got a chance to look at... ? https://github.com/processing/processing-sound/issues/95#issuecomment-1873592444

kevinstadler commented 10 months ago

Sorry for the delay, I finally looked into it and found a workaround that might work for you: it looks like sound.play() does not work only when it is called after the sound is plugged into the FFT analyzer. If the sound is already playing back, it can be safely connected to the FFT without affecting sound output.

  music = new SoundFile( this, dataPath("something.mp3"));
  FFT fft = new FFT(this, 64);

  // soundfile not audible if called in this order
  fft.input(music);
  music.play();

  // everything fine if called in this order
  music.play();
  fft.input(music);

I will look into a permanent solution, but you might be able to fix your sketch with a workaround.

bigboss97 commented 10 months ago

Thanks for the response. I'll use the workaround to try out on some songs which have a too slow playback on v2.3.

pixmusix commented 10 months ago

I got interested in this thread and decided to go checkout the fft object in the repo. From this file I found the below code excerpt.

protected void setInput(UnitOutputPort input) {
  // superclass makes sure that input unit is actually playing, just connect it
  Engine.getEngine().add(this.fft);
  this.fft.input.connect(input);
  this.fft.start();
}

The code comment implies the author was aware of the need to have the audio playing but felt convinced the setInput function doesn't need to check for it. I'm not too sure what he meant by the superclass. Any thoughts as to what the author might have meant @kevinstadler ??

Pix ❣️

bigboss97 commented 9 months ago

I will look into a permanent solution, but you might be able to fix your sketch with a workaround.

I've added two lines to workaround and that works perfectly:

  music.pause();
  fft.input( music);
  music.stop();

I tried v2.4 on some MP3's. Those used to run too slow on v2.3. Now they are fine. Also those were fail to play. Now they are all good. Well done! Can't wait to see the fix, thanks.

bigboss97 commented 9 months ago

I use my workaround to get the audio played. When I run the below code the spectrum remains 0.0. But it works with v2.3. This is probably a separate issue.

import processing.sound.*;
SoundFile  music;
FFT  fft;
float[] spectrum = new float[16];

void setup (){
  music= new SoundFile( this, dataPath("cheering.mp3"));
  fft = new FFT(this, 64);
  music.pause();

  fft.input( music);
  music.stop();
  music.play();
}

void draw() {
  fft.analyze(spectrum);
  println( spectrum[0]);
}
bigboss97 commented 9 months ago

Did you get a chance to look into that?

bigboss97 commented 9 months ago

Any update? I'm still very interested in using v2.4.

bigboss97 commented 8 months ago

Still hope to see an update here.

kevinstadler commented 8 months ago

Sorry for the delay on this one:

I got interested in this thread and decided to go checkout the fft object in the repo. From this file I found the below code excerpt.

protected void setInput(UnitOutputPort input) {
  // superclass makes sure that input unit is actually playing, just connect it
  Engine.getEngine().add(this.fft);
  this.fft.input.connect(input);
  this.fft.start();
}

The code comment implies the author was aware of the need to have the audio playing but felt convinced the setInput function doesn't need to check for it. I'm not too sure what he meant by the superclass.

The superclass refers to the public input() method from which setInput() is called, which takes care of adding the input circuit to the synthesis engine in case it hasn't been added yet (i.e. isn't currently playing): https://github.com/processing/processing-sound/blob/75e4d7b41d6eb83119dd991e3aef47cf4569acad/src/processing/sound/Analyzer.java#L25-L45

The current issue seems to be a different one though: it looks like the FFT analyzer is consuming data from the input source, only when that source's playback is started only after connecting to the analyzer, the source's output (or rather its JSynCircuit) is for some reason not routed to audio out.

kevinstadler commented 8 months ago

The issue was in the way that played back units were (unnecessarily) only selectively connected to outputs when they were already part of the synth network (such as when they are already connected to an analyzer unit), introduced in a52fa9d.

@bigboss97 if you could test this sound.jar (just replace the sound.jar in your Processing/libraries/sound/library folder), hopefully everything will work just the way it used to!

(Leaving this issue open because there remains an AudioSample/SoundFile-specific bug where Analyzers get disconnected from the inputs when their playback runs out, causing them to be removed from the synth network...)

bigboss97 commented 8 months ago

I compared the new sound.jar with the default one in lib-2.4, no difference:

  fft.input( music);
  music.stop();
  music.play();

With stop(), it plays sound, but all spectrum values are zero. Without stop() , no sound, but values in spectrum.

kevinstadler commented 8 months ago

With this sound.jar it is not necessary to use the stop() workaround anymore, just using either of the following (like in your original code) should work:

fft.input(music);
music.play();

or

music.play();
fft.input(music);

The issue with stop() is because any analyser currently gets disconnected from AudioSamples/SoundFiles once playback runs out -- fix for this is in the making...

kevinstadler commented 8 months ago

@bigboss97 this sound.jar should also stop soundfiles from getting disconnected when they are stopped!

bigboss97 commented 8 months ago

This is working perfectly:

  music.play();
  fft.input( music);

But no sound after swap:

  fft.input( music);
  music.play();

It's not a big deal. I can swap the commands in my codes. Thanks for the fix.

kevinstadler commented 8 months ago

This is working perfectly:

  music.play();
  fft.input( music);

But no sound after swap:

  fft.input( music);
  music.play();

It's not a big deal. I can swap the commands in my codes. Thanks for the fix.

Hmmm that is strange. Since you are on Windows, you might have to quit Processing, replace the sound.jar, then start Processing up again for the new version to take effect. Hopefully after doing that the two versions of the code should work exactly the same!

bigboss97 commented 8 months ago

Yes, I always close Processing whenever I change library files. It doesn't let me rename or move if Processing is running. I also tested with 2x play() then the sound is back:

  fft.input( music);
  music.play();
  music.play();
bigboss97 commented 8 months ago

I've been testing the new library on many MP3 files. Those files which were having issues in v2.3, e.g. incorrect speed, unable to open, are all good now. Well done!👍 Thanks for your effort. It was worth to wait for the version 2.4 😊