src/audio/psp/SDL_pspaudio.c
changeset 7191 75360622e65f
parent 7038 7f22b9ba218f
child 7663 53fe1b64eb2d
     1.1 --- a/src/audio/psp/SDL_pspaudio.c	Sat May 18 12:48:50 2013 -0700
     1.2 +++ b/src/audio/psp/SDL_pspaudio.c	Sat May 18 14:17:52 2013 -0700
     1.3 @@ -42,28 +42,28 @@
     1.4  static int
     1.5  PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
     1.6  {
     1.7 -	int format, mixlen, i;
     1.8 +    int format, mixlen, i;
     1.9      this->hidden = (struct SDL_PrivateAudioData *)
    1.10          SDL_malloc(sizeof(*this->hidden));
    1.11      if (this->hidden == NULL) {
    1.12          return SDL_OutOfMemory();
    1.13      }
    1.14      SDL_memset(this->hidden, 0, sizeof(*this->hidden));
    1.15 -	switch (this->spec.format & 0xff) {
    1.16 -		case 8:
    1.17 -		case 16:
    1.18 -			this->spec.format = AUDIO_S16LSB;
    1.19 -			break;
    1.20 -		default:
    1.21 -			return SDL_SetError("Unsupported audio format");
    1.22 -	}
    1.23 +    switch (this->spec.format & 0xff) {
    1.24 +        case 8:
    1.25 +        case 16:
    1.26 +            this->spec.format = AUDIO_S16LSB;
    1.27 +            break;
    1.28 +        default:
    1.29 +            return SDL_SetError("Unsupported audio format");
    1.30 +    }
    1.31  
    1.32 -	/* The sample count must be a multiple of 64. */
    1.33 -	this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
    1.34 -	this->spec.freq = 44100;
    1.35 +    /* The sample count must be a multiple of 64. */
    1.36 +    this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
    1.37 +    this->spec.freq = 44100;
    1.38  
    1.39 -	/* Update the fragment size as size in bytes. */
    1.40 -//	SDL_CalculateAudioSpec(this->spec); MOD
    1.41 +    /* Update the fragment size as size in bytes. */
    1.42 +//  SDL_CalculateAudioSpec(this->spec); MOD
    1.43      switch (this->spec.format) {
    1.44      case AUDIO_U8:
    1.45          this->spec.silence = 0x80;
    1.46 @@ -75,86 +75,86 @@
    1.47      this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
    1.48      this->spec.size *= this->spec.channels;
    1.49      this->spec.size *= this->spec.samples;
    1.50 -    
    1.51 +
    1.52  //==========================================
    1.53  
    1.54 -	/* Allocate the mixing buffer.  Its size and starting address must
    1.55 -	   be a multiple of 64 bytes.  Our sample count is already a multiple of
    1.56 -	   64, so spec->size should be a multiple of 64 as well. */
    1.57 -	mixlen = this->spec.size * NUM_BUFFERS;
    1.58 -	this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
    1.59 -	if (this->hidden->rawbuf == NULL) {
    1.60 -		return SDL_SetError("Couldn't allocate mixing buffer");
    1.61 -	}
    1.62 +    /* Allocate the mixing buffer.  Its size and starting address must
    1.63 +       be a multiple of 64 bytes.  Our sample count is already a multiple of
    1.64 +       64, so spec->size should be a multiple of 64 as well. */
    1.65 +    mixlen = this->spec.size * NUM_BUFFERS;
    1.66 +    this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
    1.67 +    if (this->hidden->rawbuf == NULL) {
    1.68 +        return SDL_SetError("Couldn't allocate mixing buffer");
    1.69 +    }
    1.70  
    1.71 -	/* Setup the hardware channel. */
    1.72 -	if (this->spec.channels == 1) {
    1.73 -		format = PSP_AUDIO_FORMAT_MONO;
    1.74 -	} else {
    1.75 -		format = PSP_AUDIO_FORMAT_STEREO;
    1.76 -	}
    1.77 -	this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
    1.78 -	if (this->hidden->channel < 0) {
    1.79 -		free(this->hidden->rawbuf);
    1.80 -		this->hidden->rawbuf = NULL;
    1.81 -		return SDL_SetError("Couldn't reserve hardware channel");
    1.82 -	}
    1.83 +    /* Setup the hardware channel. */
    1.84 +    if (this->spec.channels == 1) {
    1.85 +        format = PSP_AUDIO_FORMAT_MONO;
    1.86 +    } else {
    1.87 +        format = PSP_AUDIO_FORMAT_STEREO;
    1.88 +    }
    1.89 +    this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
    1.90 +    if (this->hidden->channel < 0) {
    1.91 +        free(this->hidden->rawbuf);
    1.92 +        this->hidden->rawbuf = NULL;
    1.93 +        return SDL_SetError("Couldn't reserve hardware channel");
    1.94 +    }
    1.95  
    1.96 -	memset(this->hidden->rawbuf, 0, mixlen);
    1.97 -	for (i = 0; i < NUM_BUFFERS; i++) {
    1.98 -		this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
    1.99 -	}
   1.100 +    memset(this->hidden->rawbuf, 0, mixlen);
   1.101 +    for (i = 0; i < NUM_BUFFERS; i++) {
   1.102 +        this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
   1.103 +    }
   1.104  
   1.105 -	this->hidden->next_buffer = 0;
   1.106 -	return 0;
   1.107 +    this->hidden->next_buffer = 0;
   1.108 +    return 0;
   1.109  }
   1.110  
   1.111  static void PSPAUD_PlayDevice(_THIS)
   1.112  {
   1.113 -	Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
   1.114 +    Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
   1.115  
   1.116 -	if (this->spec.channels == 1) {
   1.117 -		sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
   1.118 -	} else {
   1.119 -		sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
   1.120 -	}
   1.121 +    if (this->spec.channels == 1) {
   1.122 +        sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
   1.123 +    } else {
   1.124 +        sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
   1.125 +    }
   1.126  
   1.127 -	this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
   1.128 +    this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
   1.129  }
   1.130  
   1.131  /* This function waits until it is possible to write a full sound buffer */
   1.132  static void PSPAUD_WaitDevice(_THIS)
   1.133  {
   1.134 -	/* Because we block when sending audio, there's no need for this function to do anything. */
   1.135 +    /* Because we block when sending audio, there's no need for this function to do anything. */
   1.136  }
   1.137  static Uint8 *PSPAUD_GetDeviceBuf(_THIS)
   1.138  {
   1.139 -	return this->hidden->mixbufs[this->hidden->next_buffer];
   1.140 +    return this->hidden->mixbufs[this->hidden->next_buffer];
   1.141  }
   1.142  
   1.143  static void PSPAUD_CloseDevice(_THIS)
   1.144  {
   1.145 -	if (this->hidden->channel >= 0) {
   1.146 -		sceAudioChRelease(this->hidden->channel);
   1.147 -		this->hidden->channel = -1;
   1.148 -	}
   1.149 +    if (this->hidden->channel >= 0) {
   1.150 +        sceAudioChRelease(this->hidden->channel);
   1.151 +        this->hidden->channel = -1;
   1.152 +    }
   1.153  
   1.154 -	if (this->hidden->rawbuf != NULL) {
   1.155 -		free(this->hidden->rawbuf);
   1.156 -		this->hidden->rawbuf = NULL;
   1.157 -	}
   1.158 +    if (this->hidden->rawbuf != NULL) {
   1.159 +        free(this->hidden->rawbuf);
   1.160 +        this->hidden->rawbuf = NULL;
   1.161 +    }
   1.162  }
   1.163  static void PSPAUD_ThreadInit(_THIS)
   1.164  {
   1.165 -	/* Increase the priority of this audio thread by 1 to put it
   1.166 -	   ahead of other SDL threads. */
   1.167 -	SceUID thid;
   1.168 -	SceKernelThreadInfo status;
   1.169 -	thid = sceKernelGetThreadId();
   1.170 -	status.size = sizeof(SceKernelThreadInfo);
   1.171 -	if (sceKernelReferThreadStatus(thid, &status) == 0) {
   1.172 -		sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
   1.173 -	}
   1.174 +    /* Increase the priority of this audio thread by 1 to put it
   1.175 +       ahead of other SDL threads. */
   1.176 +    SceUID thid;
   1.177 +    SceKernelThreadInfo status;
   1.178 +    thid = sceKernelGetThreadId();
   1.179 +    status.size = sizeof(SceKernelThreadInfo);
   1.180 +    if (sceKernelReferThreadStatus(thid, &status) == 0) {
   1.181 +        sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
   1.182 +    }
   1.183  }
   1.184  
   1.185  
   1.186 @@ -162,17 +162,17 @@
   1.187  PSPAUD_Init(SDL_AudioDriverImpl * impl)
   1.188  {
   1.189  
   1.190 -    // Set the function pointers 
   1.191 +    // Set the function pointers
   1.192      impl->OpenDevice = PSPAUD_OpenDevice;
   1.193      impl->PlayDevice = PSPAUD_PlayDevice;
   1.194      impl->WaitDevice = PSPAUD_WaitDevice;
   1.195 -    impl->GetDeviceBuf = PSPAUD_GetDeviceBuf;   
   1.196 +    impl->GetDeviceBuf = PSPAUD_GetDeviceBuf;
   1.197      impl->WaitDone = PSPAUD_WaitDevice;
   1.198      impl->CloseDevice = PSPAUD_CloseDevice;
   1.199      impl->ThreadInit = PSPAUD_ThreadInit;
   1.200 -    
   1.201 +
   1.202      //PSP audio device
   1.203 -    impl->OnlyHasDefaultOutputDevice = 1;    
   1.204 +    impl->OnlyHasDefaultOutputDevice = 1;
   1.205  /*
   1.206      impl->HasCaptureSupport = 1;
   1.207