-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug: SPU stereo recording to wav file
- Loading branch information
1 parent
47bbec1
commit f2bf793
Showing
9 changed files
with
114 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "wave.h" | ||
|
||
namespace wave { | ||
bool writeToFile(const std::vector<uint16_t>& buffer, const char* filename, int channels) { | ||
FILE* f = fopen(filename, "wb"); | ||
if (!f) { | ||
return false; | ||
} | ||
auto wstr = [&](const char* str) { fwrite(str, 1, strlen(str), f); }; | ||
auto w32 = [f](uint32_t i) { fwrite(&i, sizeof(i), 1, f); }; | ||
auto w16 = [f](uint16_t i) { fwrite(&i, sizeof(i), 1, f); }; | ||
|
||
const int bitPerSample = 16; | ||
const int sampleRate = 44100; | ||
|
||
wstr("RIFF"); | ||
w32((buffer.size() * bitPerSample / 8) + 36); | ||
|
||
wstr("WAVE"); | ||
wstr("fmt "); | ||
w32(16); // Subchunk size | ||
w16(1); // PCM | ||
w16(channels); | ||
w32(sampleRate); | ||
w32(sampleRate * channels * bitPerSample / 8); | ||
w16(channels * bitPerSample / 8); | ||
w16(bitPerSample); | ||
|
||
wstr("data"); | ||
w32(buffer.size() * bitPerSample / 8); | ||
for (uint16_t s : buffer) { | ||
w16(s); | ||
} | ||
|
||
fclose(f); | ||
return true; | ||
} | ||
}; // namespace wave |
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,6 @@ | ||
#pragma once | ||
#include <vector> | ||
|
||
namespace wave { | ||
bool writeToFile(const std::vector<uint16_t>& buffer, const char* filename, int channels = 2); | ||
}; |