1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-15 09:34:18 +02:00
This commit is contained in:
XProger
2017-05-16 02:44:21 +03:00
2 changed files with 35 additions and 9 deletions

View File

@@ -44,6 +44,8 @@
#ifdef _MSC_VER #ifdef _MSC_VER
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
typedef signed __int64 int64_t; typedef signed __int64 int64_t;
#elif defined(__x86_64__) && defined(__linux__)
#include <sys/types.h>
#else #else
typedef unsigned long long uint64_t; typedef unsigned long long uint64_t;
typedef signed long long int64_t; typedef signed long long int64_t;

View File

@@ -194,10 +194,22 @@ class Sound {
int rate = 44100; int rate = 44100;
int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
//System.out.println(String.format("sound buffer size: %d", bufSize)); //System.out.println(String.format("sound buffer size: %d", bufSize));
buffer = new short [size / 2]; buffer = new short[size / 2];
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT, size, AudioTrack.MODE_STREAM); try {
audioTrack.play(); audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT, size, AudioTrack.MODE_STREAM);
}catch (IllegalArgumentException e){
System.out.println("Error: buffer size is zero");
return;
}
try {
audioTrack.play();
}catch (NullPointerException e){
System.out.println("Error: audioTrack null pointer on start()");
return;
}
new Thread( new Runnable() { new Thread( new Runnable() {
public void run() { public void run() {
@@ -220,17 +232,29 @@ class Sound {
} }
void stop() { void stop() {
audioTrack.flush(); try {
audioTrack.stop(); audioTrack.flush();
audioTrack.release(); audioTrack.stop();
audioTrack.release();
}catch (NullPointerException e){
System.out.println("Error: audioTrack null pointer on stop()");
}
} }
void play() { void play() {
audioTrack.play(); try {
audioTrack.play();
}catch (NullPointerException e){
System.out.println("Error: audioTrack null pointer on play()");
}
} }
void pause() { void pause() {
audioTrack.pause(); try {
audioTrack.pause();
}catch (NullPointerException e){
System.out.println("Error: audioTrack null pointer on pause()");
};
} }
} }