Skip to content

Commit

Permalink
Clip channel count to prevent overflow (#3)
Browse files Browse the repository at this point in the history
A bug in the JavaSound device code could cause Issue #1.

Build new FreeHorn.jar

For diagnosing #1
  • Loading branch information
philburk authored Feb 5, 2023
1 parent 6b5e728 commit 39be37a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Binary file modified FreeHorn.jar
Binary file not shown.
30 changes: 27 additions & 3 deletions jsrc/org/frogpeak/horn/TJ_Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* <P>
* The underlying device interface is based on the PortAudio library which is
* available at http://www.portaudio.com
*
*
* @author (C) 2001-2007 Phil Burk, Mobileer Inc, All Rights Reserved
*/

Expand All @@ -45,6 +45,9 @@ public class TJ_Devices extends Applet
public final static int INPUT_MODE = 0;
public final static int OUTPUT_MODE = 1;


private final static int MAX_NUM_CHANNELS = 16;

/* Can be run as either an application or as an applet. */
public static void main( String args[] )
{
Expand Down Expand Up @@ -187,6 +190,7 @@ void startAudio()
freeHorn.finalizeSetup();
}

@Override
public void stop()
{
try
Expand Down Expand Up @@ -247,6 +251,7 @@ class DeviceMenuItem
maxChannels = pMaxChannels;
}

@Override
public String toString()
{
return name + " [" + maxChannels + "]";
Expand Down Expand Up @@ -304,7 +309,16 @@ public DeviceSelector(String text, int mode, TJ_Devices devices)
int defaultSelection = 0;
// Loop though all of the available devices and fill
// the choice menu with valid options.
for( int i = 0; i < AudioDevice.getNumDevices(); i++ )
int numDevices = AudioDevice.getNumDevices();
System.out.println("TJ_Devices mode = " + mode
+ ", numDevices = " + numDevices);
final int MAX_NUM_DEVICES = 32;
if (numDevices > MAX_NUM_DEVICES) {
System.out.println("TJ_Devices numDevices too high! Clip to "
+ MAX_NUM_DEVICES);
numDevices = MAX_NUM_DEVICES;
}
for( int i = 0; i < numDevices; i++ )
{
int maxChannels = getMaxChannels( i );
if( maxChannels > 0 )
Expand Down Expand Up @@ -370,7 +384,16 @@ public int getMaxChannels( int id )
int maxChannels = (mode == INPUT_MODE) ? AudioDevice
.getMaxInputChannels( id ) : AudioDevice
.getMaxOutputChannels( id );
return maxChannels;

System.out.println("TJ_Devices.getMaxChannels() id = " + id
+ ", maxChannels = " + maxChannels);

if (maxChannels > MAX_NUM_CHANNELS) {
System.out.println("TJ_Devices maxChannels too high! Clip to "
+ MAX_NUM_CHANNELS);
maxChannels = MAX_NUM_CHANNELS;
}
return maxChannels;
}

/*public void setNumChannels( int numChannels )
Expand Down Expand Up @@ -454,6 +477,7 @@ public void buildChannelArray(){
}


@Override
public void itemStateChanged(ItemEvent e) {
if(e.getItemSelectable() == deviceNames){
buildChannelArray();
Expand Down

0 comments on commit 39be37a

Please sign in to comment.