changeset 13:92b416b4e027

fixed all problems for 16 bit mono output
author Robert McIntyre <rlm@mit.edu>
date Mon, 31 Oct 2011 07:44:02 -0700
parents 9558b856ebdf
children 63312ec4a2bf
files Alc/backends/send.c java/src/com/aurellem/send/AudioSend.java
diffstat 2 files changed, 81 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/Alc/backends/send.c	Mon Oct 31 03:33:37 2011 -0700
     1.2 +++ b/Alc/backends/send.c	Mon Oct 31 07:44:02 2011 -0700
     1.3 @@ -188,7 +188,9 @@
     1.4    // create context_data and add it to the main array
     1.5    context_data *ctxData;
     1.6    ctxData = (context_data*)calloc(1, sizeof(*ctxData));
     1.7 -  ctxData->renderBuffer = malloc(data->size);
     1.8 +  ctxData->renderBuffer = 
     1.9 +    malloc(BytesFromDevFmt(Device->FmtType) * 
    1.10 +	   Device->NumChan * Device->UpdateSize);
    1.11    ctxData->ctx = context;
    1.12  
    1.13    data->contexts[data->numContexts] = ctxData;
    1.14 @@ -302,10 +304,19 @@
    1.15    ALCdevice *recorder = (ALCdevice*) ((intptr_t)device);
    1.16    send_data *data = (send_data*)recorder->ExtraData;
    1.17    if ((ALuint)n > data->numContexts){return;}
    1.18 -  if ((uint) samples > data->size){
    1.19 -    samples = (int) data->size;
    1.20 -  }
    1.21 -  memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*sizeof(ALfloat));
    1.22 +  //if ((uint) samples > data->size){
    1.23 +  //  samples = (int) data->size;
    1.24 +  //}
    1.25 +  printf("Want %d samples for listener %d\n", samples, n);
    1.26 +  printf("Device's format type is %d bytes per sample,\n", 
    1.27 +	  BytesFromDevFmt(recorder->FmtType));
    1.28 +  printf("and it has %d channels, making for %d requested bytes\n", 
    1.29 +	 recorder->NumChan, 
    1.30 +	 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples);
    1.31 +
    1.32 +  memcpy(buffer_address, data->contexts[n]->renderBuffer, 
    1.33 +	 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples);
    1.34 +  //samples*sizeof(ALfloat));
    1.35  }
    1.36  
    1.37  /*
    1.38 @@ -378,6 +389,51 @@
    1.39  }
    1.40  
    1.41  
    1.42 +/*
    1.43 + * Class:     com_aurellem_send_AudioSend
    1.44 + * Method:    ngetAudioFormat
    1.45 + * Signature: (J)Ljavax/sound/sampled/AudioFormat;
    1.46 + */
    1.47 +JNIEXPORT jobject JNICALL Java_com_aurellem_send_AudioSend_ngetAudioFormat
    1.48 +(JNIEnv *env, jclass clazz, jlong device){
    1.49 +  UNUSED(clazz);
    1.50 +  jclass AudioFormatClass = 
    1.51 +    (*env)->FindClass(env, "javax/sound/sampled/AudioFormat");
    1.52 +  jmethodID AudioFormatConstructor = 
    1.53 +    (*env)->GetMethodID(env, AudioFormatClass, "<init>", "(FIIZZ)V");
    1.54 +  
    1.55 +  ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
    1.56 +
    1.57 +  //float frequency
    1.58 +
    1.59 +  int isSigned;
    1.60 +  switch (Device->FmtType)
    1.61 +    {
    1.62 +    case DevFmtUByte: 
    1.63 +    case DevFmtUShort: isSigned = 0; break;  
    1.64 +    default : isSigned = 1;   
    1.65 +    }
    1.66 +  float frequency = Device->Frequency;
    1.67 +  int bitsPerFrame = (8 * BytesFromDevFmt(Device->FmtType));
    1.68 +  int channels = Device->NumChan;
    1.69 +
    1.70 +
    1.71 +  printf("freq = %f, bpf = %d, channels = %d, signed? = %d\n",
    1.72 +	 frequency, bitsPerFrame, channels, isSigned);
    1.73 +
    1.74 +  jobject format = (*env)->
    1.75 +    NewObject(
    1.76 +	      env,AudioFormatClass,AudioFormatConstructor,
    1.77 +	      frequency,
    1.78 +	      bitsPerFrame,
    1.79 +	      channels,
    1.80 +	      isSigned,
    1.81 +	      0);
    1.82 +  return format;
    1.83 +}
    1.84 +
    1.85 +
    1.86 +
    1.87  ////////////////////   Device Initilization / Management
    1.88  
    1.89  static const ALCchar sendDevice[] = "Multiple Audio Send";
    1.90 @@ -419,13 +475,13 @@
    1.91  
    1.92  static ALCboolean send_reset_playback(ALCdevice *device)
    1.93  {
    1.94 -  send_data *data = (send_data*)device->ExtraData;
    1.95 -  ALuint channels=0, bits=0;
    1.96 -  device->FmtType = DevFmtShort;
    1.97 -  bits = BytesFromDevFmt(device->FmtType) * 8;
    1.98 -  channels = ChannelsFromDevFmt(device->FmtChans);
    1.99 -  data->size = device->UpdateSize * channels * bits / 8;
   1.100 -
   1.101 +  //send_data *data = (send_data*)device->ExtraData;
   1.102 +  //ALuint channels=0, bits=0;
   1.103 +  //device->FmtType = DevFmtShort;
   1.104 +  //bits = BytesFromDevFmt(device->FmtType) * 8;
   1.105 +  //channels = ChannelsFromDevFmt(device->FmtChans);
   1.106 +  //data->size = device->UpdateSize * channels * bits / 8;
   1.107 +  SetDefaultWFXChannelOrder(device);
   1.108    return ALC_TRUE;
   1.109  }
   1.110  
     2.1 --- a/java/src/com/aurellem/send/AudioSend.java	Mon Oct 31 03:33:37 2011 -0700
     2.2 +++ b/java/src/com/aurellem/send/AudioSend.java	Mon Oct 31 07:44:02 2011 -0700
     2.3 @@ -2,6 +2,8 @@
     2.4  
     2.5  import java.nio.ByteBuffer;
     2.6  
     2.7 +import javax.sound.sampled.AudioFormat;
     2.8 +
     2.9  public class AudioSend {
    2.10  
    2.11  	private final long deviceID;
    2.12 @@ -75,4 +77,15 @@
    2.13  		nsetNthListenerf(pname, v1, this.deviceID, contextNum);}
    2.14  	public static native void nsetNthListenerf(int pname, float v1, long device, int contextNum);
    2.15  	
    2.16 +	
    2.17 +	/**
    2.18 +	 * Retrieve the AudioFormat which the device is using.  This format is itself derived
    2.19 +	 * from the OpenAL config file under the "format" variable.
    2.20 +	 */
    2.21 +	public AudioFormat getAudioFormat(){
    2.22 +		return ngetAudioFormat(this.deviceID);}
    2.23 +	public static native AudioFormat ngetAudioFormat(long device);
    2.24 +	
    2.25 +	
    2.26 +	
    2.27  }