Mercurial > sdl-ios-xcode
comparison android/testproject/jni/lesson05.c @ 4722:faa228f7ce5b
- Cleaned up a bunch of code
- Added 'feature' enable/disable so we're not running accel/sound/whatever in Java when we don't need to be
- More work on the sound system. But it still crashes pretty horribly, not sure why yet.
author | Paul Hunkin <paul@bieh.net> |
---|---|
date | Tue, 27 Jul 2010 21:21:24 +0200 |
parents | d59792d2c3ae |
children | 74da47b2f5b7 |
comparison
equal
deleted
inserted
replaced
4721:7bb9d3a3f257 | 4722:faa228f7ce5b |
---|---|
11 */ | 11 */ |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <math.h> | 15 #include <math.h> |
16 | |
17 #include <signal.h> | |
16 | 18 |
17 #include <android/log.h> | 19 #include <android/log.h> |
18 | 20 |
19 | 21 |
20 #ifdef ANDROID | 22 #ifdef ANDROID |
351 rotation++; | 353 rotation++; |
352 | 354 |
353 return( TRUE ); | 355 return( TRUE ); |
354 } | 356 } |
355 | 357 |
358 | |
359 struct | |
360 { | |
361 SDL_AudioSpec spec; | |
362 Uint8 *sound; /* Pointer to wave data */ | |
363 Uint32 soundlen; /* Length of wave data */ | |
364 int soundpos; /* Current play position */ | |
365 } wave; | |
366 | |
367 void SDLCALL | |
368 fillerup(void *unused, Uint8 * stream, int len) | |
369 { | |
370 __android_log_print(ANDROID_LOG_INFO, "SDL","FILLERUP\n"); | |
371 | |
372 Uint8 *waveptr; | |
373 int waveleft; | |
374 | |
375 /* Set up the pointers */ | |
376 waveptr = wave.sound + wave.soundpos; | |
377 waveleft = wave.soundlen - wave.soundpos; | |
378 | |
379 /* Go! */ | |
380 while (waveleft <= len) { | |
381 SDL_memcpy(stream, waveptr, waveleft); | |
382 stream += waveleft; | |
383 len -= waveleft; | |
384 waveptr = wave.sound; | |
385 waveleft = wave.soundlen; | |
386 wave.soundpos = 0; | |
387 } | |
388 SDL_memcpy(stream, waveptr, len); | |
389 wave.soundpos += len; | |
390 } | |
391 | |
392 void testAudio(){ | |
393 | |
394 const char *file = "/sdcard/sample.wav"; | |
395 | |
396 /* Load the SDL library */ | |
397 if (SDL_Init(SDL_INIT_AUDIO) < 0) { | |
398 __android_log_print(ANDROID_LOG_INFO, "SDL","Couldn't initialize SDL Audio: %s\n", SDL_GetError()); | |
399 return; | |
400 }else{ | |
401 __android_log_print(ANDROID_LOG_INFO, "SDL","Init audio ok\n"); | |
402 } | |
403 | |
404 /* Load the wave file into memory */ | |
405 if (SDL_LoadWAV(file, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { | |
406 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't load %s: %s\n", file, SDL_GetError()); | |
407 return; | |
408 } | |
409 | |
410 wave.spec.callback = fillerup; | |
411 | |
412 __android_log_print(ANDROID_LOG_INFO, "SDL","Loaded: %d\n", wave.soundlen); | |
413 | |
414 | |
415 /* Initialize fillerup() variables */ | |
416 if (SDL_OpenAudio(&wave.spec, NULL) < 0) { | |
417 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't open audio: %s\n", SDL_GetError()); | |
418 SDL_FreeWAV(wave.sound); | |
419 return; | |
420 } | |
421 | |
422 __android_log_print(ANDROID_LOG_INFO, "SDL","Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); | |
423 | |
424 /* Let the audio run */ | |
425 SDL_PauseAudio(0); | |
426 | |
427 __android_log_print(ANDROID_LOG_INFO, "SDL","Playing\n"); | |
428 | |
429 while (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING){ | |
430 //__android_log_print(ANDROID_LOG_INFO, "SDL","Still playing\n"); | |
431 //SDL_Delay(100); | |
432 } | |
433 | |
434 __android_log_print(ANDROID_LOG_INFO, "SDL","Closing down\n"); | |
435 | |
436 /* Clean up on signal */ | |
437 SDL_CloseAudio(); | |
438 SDL_FreeWAV(wave.sound); | |
439 } | |
440 | |
356 int SDL_main( int argc, char **argv ) | 441 int SDL_main( int argc, char **argv ) |
357 { | 442 { |
358 | 443 |
359 __android_log_print(ANDROID_LOG_INFO, "SDL","entry\n"); | 444 __android_log_print(ANDROID_LOG_INFO, "SDL","entry\n"); |
360 | 445 |
423 initGL( ); | 508 initGL( ); |
424 | 509 |
425 /* resize the initial window */ | 510 /* resize the initial window */ |
426 resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); | 511 resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); |
427 | 512 |
428 /* Load the SDL library */ | 513 |
429 if (SDL_Init(SDL_INIT_AUDIO) < 0) { | 514 testAudio(); |
430 __android_log_print(ANDROID_LOG_INFO, "SDL","Couldn't initialize SDL Audio: %s\n", SDL_GetError()); | |
431 return (1); | |
432 }else{ | |
433 __android_log_print(ANDROID_LOG_INFO, "SDL","Init audio ok\n"); | |
434 } | |
435 | 515 |
436 | 516 |
437 /* wait for events */ | 517 /* wait for events */ |
438 while ( !done ) | 518 while ( !done ) |
439 { | 519 { |