add sample rate parameter in raw sample import

This commit is contained in:
tildearrow 2024-01-16 21:12:34 -05:00
parent ab3624789b
commit 928bfd2afd
4 changed files with 16 additions and 6 deletions

View file

@ -954,7 +954,7 @@ class DivEngine {
DivSample* sampleFromFile(const char* path);
// get raw sample
DivSample* sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles);
DivSample* sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles, int rate);
// delete sample
void delSample(int index);

View file

@ -302,7 +302,7 @@ DivSample* DivEngine::sampleFromFile(const char* path) {
#endif
}
DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles) {
DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles, int rate) {
if (song.sample.size()>=256) {
lastError="too many samples!";
return NULL;
@ -420,8 +420,8 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
return NULL;
}
sample->rate=32000;
sample->centerRate=32000;
sample->rate=rate;
sample->centerRate=rate;
sample->depth=depth;
sample->init(samples);

View file

@ -5988,6 +5988,15 @@ bool FurnaceGUI::loop() {
pendingRawSampleBigEndian=false;
}
ImGui::AlignTextToFramePadding();
ImGui::Text("Sample rate");
ImGui::SameLine();
ImGui::SetNextItemWidth(120.0f*dpiScale);
if (ImGui::InputInt("##RSRate",&pendingRawSampleRate,100,1000)) {
if (pendingRawSampleRate<100) pendingRawSampleRate=100;
if (pendingRawSampleRate>384000) pendingRawSampleRate=384000;
}
if (pendingRawSampleDepth==DIV_SAMPLE_DEPTH_8BIT || pendingRawSampleDepth==DIV_SAMPLE_DEPTH_16BIT) {
ImGui::AlignTextToFramePadding();
ImGui::Text("Channels");
@ -6033,7 +6042,7 @@ bool FurnaceGUI::loop() {
}
if (ImGui::Button("OK")) {
DivSample* s=e->sampleFromFileRaw(pendingRawSample.c_str(),(DivSampleDepth)pendingRawSampleDepth,pendingRawSampleChannels,pendingRawSampleBigEndian,pendingRawSampleUnsigned,pendingRawSampleSwapNibbles);
DivSample* s=e->sampleFromFileRaw(pendingRawSample.c_str(),(DivSampleDepth)pendingRawSampleDepth,pendingRawSampleChannels,pendingRawSampleBigEndian,pendingRawSampleUnsigned,pendingRawSampleSwapNibbles,pendingRawSampleRate);
if (s==NULL) {
showError(e->getLastError());
} else {
@ -7225,6 +7234,7 @@ FurnaceGUI::FurnaceGUI():
editString(NULL),
pendingRawSampleDepth(8),
pendingRawSampleChannels(1),
pendingRawSampleRate(32000),
pendingRawSampleUnsigned(false),
pendingRawSampleBigEndian(false),
pendingRawSampleSwapNibbles(false),

View file

@ -1497,7 +1497,7 @@ class FurnaceGUI {
SDL_Event userEvent;
String pendingRawSample;
int pendingRawSampleDepth, pendingRawSampleChannels;
int pendingRawSampleDepth, pendingRawSampleChannels, pendingRawSampleRate;
bool pendingRawSampleUnsigned, pendingRawSampleBigEndian, pendingRawSampleSwapNibbles, pendingRawSampleReplace;
ImGuiWindowFlags globalWinFlags;