-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple sound effects
- Loading branch information
1 parent
6cc3456
commit e7e58b0
Showing
25 changed files
with
199 additions
and
37 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
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,14 @@ | ||
#pragma once | ||
|
||
#include <AudioEngineFileLoader.h> | ||
|
||
#import <Foundation/NSURL.h> | ||
|
||
namespace linguine::alfredo { | ||
|
||
class MacAudioEngineFileLoader : public audio::AudioEngineFileLoader { | ||
public: | ||
NSURL* getUrlForEffect(EffectType effectType) override; | ||
}; | ||
|
||
} // namespace linguine::alfredo |
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,25 @@ | ||
#include "MacAudioEngineFileLoader.h" | ||
|
||
namespace linguine::alfredo { | ||
|
||
NSURL* MacAudioEngineFileLoader::getUrlForEffect(EffectType effectType) { | ||
NSString* path; | ||
|
||
switch (effectType) { | ||
case Pop: | ||
path = @"Balloon Pop 1.wav"; | ||
break; | ||
case Select: | ||
path = @"Select 1.wav"; | ||
break; | ||
} | ||
|
||
if (path) { | ||
return [NSURL fileURLWithPath:path | ||
isDirectory:false]; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
} // namespace linguine::alfredo |
Binary file not shown.
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
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,23 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#import <AVFoundation/AVAudioFile.h> | ||
|
||
#include <audio/EffectType.h> | ||
|
||
namespace linguine::audio { | ||
|
||
class AudioEngineFileLoader { | ||
public: | ||
virtual ~AudioEngineFileLoader() = default; | ||
|
||
AVAudioFile* getAudioFileForEffect(EffectType effectType); | ||
|
||
virtual NSURL* getUrlForEffect(EffectType effectType) = 0; | ||
|
||
private: | ||
std::unordered_map<EffectType, AVAudioFile*> _loadedFiles; | ||
}; | ||
|
||
} // namespace linguine::audio |
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,28 @@ | ||
#include "AudioEngineFileLoader.h" | ||
|
||
namespace linguine::audio { | ||
|
||
AVAudioFile* AudioEngineFileLoader::getAudioFileForEffect(EffectType effectType) { | ||
auto existing = _loadedFiles.find(effectType); | ||
|
||
if (existing != _loadedFiles.end()) { | ||
return existing->second; | ||
} | ||
|
||
auto url = getUrlForEffect(effectType); | ||
|
||
NSError* error; | ||
auto file = [[AVAudioFile alloc] initForReading:url | ||
error:&error]; | ||
|
||
if (error) { | ||
NSLog(@"%@", [error localizedDescription]); | ||
return nil; | ||
} | ||
|
||
_loadedFiles.insert({effectType, file}); | ||
|
||
return file; | ||
} | ||
|
||
} // namespace linguine::audio |
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
4 changes: 3 additions & 1 deletion
4
linguine/include/AudioManager.h → linguine/include/audio/AudioManager.h
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
#pragma once | ||
|
||
#include "EffectType.h" | ||
|
||
namespace linguine { | ||
|
||
class AudioManager { | ||
public: | ||
virtual ~AudioManager() = default; | ||
|
||
virtual void play() = 0; | ||
virtual void play(EffectType effectType) = 0; | ||
}; | ||
|
||
} // namespace linguine |
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,10 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
enum EffectType { | ||
Pop, | ||
Select | ||
}; | ||
|
||
} // namespace linguine |
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
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
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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
#include "System.h" | ||
|
||
#include "AudioManager.h" | ||
#include "audio/AudioManager.h" | ||
|
||
namespace linguine { | ||
|
||
|
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
Oops, something went wrong.