This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of how audio could be implemented (#19)
- Loading branch information
Showing
1 changed file
with
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module scone.audio.audio; | ||
|
||
interface StandardAudio | ||
{ | ||
|
||
} | ||
|
||
class DummyAudio : StandardAudio | ||
{ | ||
|
||
} | ||
|
||
alias AudioId = size_t; | ||
|
||
class Audio | ||
{ | ||
this(StandardAudio standardAudio) | ||
{ | ||
|
||
} | ||
|
||
AudioId register(string path) | ||
{ | ||
this.tempAudioIdCounter++; | ||
return tempAudioIdCounter; | ||
} | ||
|
||
AudioHandle play(AudioId id) | ||
{ | ||
return new AudioHandle(id); | ||
} | ||
|
||
void stop(ref AudioHandle handle) | ||
{ | ||
handle = null; | ||
} | ||
|
||
private uint tempAudioIdCounter; | ||
} | ||
|
||
class AudioHandle | ||
{ | ||
this(AudioId id) | ||
{ | ||
this.id = id; | ||
} | ||
|
||
private AudioId id; | ||
} | ||
|
||
unittest | ||
{ | ||
auto standardAudio = new DummyAudio(); | ||
auto audio = new Audio(standardAudio); | ||
|
||
auto audioId1 = audio.register("audio/snd1"); | ||
auto audioId2 = audio.register("audio/snd1"); | ||
|
||
assert(audioId1 != audioId2); | ||
|
||
auto audioHandle1 = audio.play(audioId1); | ||
assert(audioHandle1 !is null); | ||
|
||
audio.stop(audioHandle1); | ||
assert(audioHandle1 is null); | ||
} |