main.cpp
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
int main(int argc, char* args[])
{
int loop = 1;
SDL_Event event;
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("%s, failed to SDL_Init\n", __func__);
return -1;
}
SDL_Surface* screen = NULL;
screen = SDL_SetVideoMode(1440, 1440, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL) {
printf("%s, failed to SDL_SetVideMode\n", __func__);
return -1;
}
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1) {
printf("failed to Mix_OpenAudio\n");
return -1;
}
SDL_ShowCursor(0);
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xff, 0x00, 0x00));
SDL_Flip(screen);
Mix_Music *music = Mix_LoadMUS("app/native/main.wav");
if (music == NULL) {
printf("failed to load main.wav\n");
return -1;
}
if (Mix_PlayingMusic() == 0) {
if (Mix_PlayMusic(music, -1) == -1) {
printf("failed to Mix_PlayMuic\n");
return -1;
}
}
SDL_Delay(3000);
Mix_HaltMusic();
//Mix_PauseMusic();
//Mix_ResumeMusic();
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0x00, 0xff, 0x00));
SDL_Flip(screen);
Mix_Chunk *effect = Mix_LoadWAV("app/native/effect.wav");
if (effect == NULL) {
printf("failed to load effect.wav\n");
return -1;
}
int cnt = 0;
for (cnt = 0; cnt < 3; cnt++) {
if (Mix_PlayChannel(-1, effect, 0) == -1) {
printf("failed to play effect.wav\n");
return -1;
}
SDL_Delay(1000);
}
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0x00, 0x00, 0xff));
SDL_Flip(screen);
Mix_FreeChunk(effect);
Mix_FreeMusic(music);
Mix_CloseAudio();
SDL_Quit();
return 0;
}
bar-descriptor.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<qnx xmlns="http://www.qnx.com/schemas/application/1.0">
<id>com.steward.sdl.ch11</id>
<name>ch11</name>
<filename>ch11</filename>
<versionNumber>1.0.0</versionNumber>
<buildId>1</buildId>
<description>Lesson 11. Playing Sounds</description>
<author>Steward</author>
<authorId>gYAAgGE4qaHzBnzEAu8JKe4G1OI</authorId>
<asset path="main" entry="true" type="Qnx/Elf">main</asset>
<asset path="main.wav">main.wav</asset>
<asset path="effect.wav">effect.wav</asset>
<asset path="lib" type="Qnx/Elf">lib</asset>
<permission system="true">run_native</permission>
<permission>access_shared</permission>
<permission>use_gamepad</permission>
<permission>play_audio</permission>
<env var="LD_LIBRARY_PATH" value="app/native/lib"/>
</qnx>
Makefile
main: main.cpp
ntoarmv7-gcc main.cpp -g -o main lib/libSDL-1.2.so.11 -Iinclude lib/libSDL_image-1.2.so.8 lib/libSDL_ttf-2.0.so.10 lib/libSDL_mixer-1.2.so.12 $(QNX_TARGET)/lib/libwebp.a
blackberry-nativepackager -package main.bar bar-descriptor.xml -devMode -debugToken ${HOME}/.rim/debugtoken_q30.bar
clean:
rm -rf main
rm -rf main.bar