-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14faca6
commit b1242c9
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// g++ -I ../soloud/include example.cpp ../../../target/debug/build/soloud-sys-69e1b085f8a6624a/out/lib/libsoloud.a | ||
|
||
#include <stdio.h> | ||
|
||
#include "soloud.h" | ||
#include "soloud_wav.h" | ||
#include "soloud_thread.h" | ||
#include <fstream> | ||
#include <vector> | ||
|
||
constexpr unsigned long BEEP_INTERVAL = 100000; //milliseconds | ||
constexpr unsigned long POLL_INTERVAL = 1000; | ||
|
||
int main() { | ||
for (int i = 0; i < 5; i++) { | ||
SoLoud::Soloud sl; | ||
SoLoud::Wav wav; | ||
sl.init(); | ||
std::ifstream in("../../../beep.mp3", ::std::ios::binary); | ||
std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(in), {}); | ||
auto ret = wav.loadMem(buffer.data(), buffer.size(), true, false); | ||
|
||
sl.play(wav); | ||
|
||
while (sl.getVoiceCount() > 0) { | ||
SoLoud::Thread::sleep(POLL_INTERVAL); | ||
} | ||
|
||
sl.deinit(); | ||
SoLoud::Thread::sleep(BEEP_INTERVAL); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use soloud::*; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
const BEEP_INTERVAL: u64 = 1000; //milliseconds | ||
const POLL_INTERVAL: u64 = 100; | ||
for _ in 0..5 { | ||
std::thread::spawn(|| { | ||
let mut sl = Soloud::default().unwrap(); | ||
sl.set_global_volume(3.0); | ||
|
||
let mut wav = audio::Wav::default(); | ||
|
||
wav.load_mem(include_bytes!("../../beep.mp3")).unwrap(); | ||
|
||
sl.play(&wav); | ||
|
||
while sl.voice_count() > 0 { | ||
std::thread::sleep(std::time::Duration::from_millis(POLL_INTERVAL)); | ||
} | ||
}); | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(BEEP_INTERVAL)); | ||
} | ||
|
||
Ok(()) | ||
} |