Skip to content

Commit

Permalink
try some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Jun 12, 2020
1 parent b5c1411 commit b16cb1c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 44 deletions.
11 changes: 10 additions & 1 deletion romsel_aktheme/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@
"filesystem": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"ratio": "cpp"
"ratio": "cpp",
"atomic": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"random": "cpp",
"iostream": "cpp",
"ranges": "cpp"
},
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.errorSquiggles": "Disabled"
Expand Down
4 changes: 2 additions & 2 deletions romsel_aktheme/arm9/source/irqs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "windows/batteryicon.h"
#include "windows/volumeicon.h"
#include "ui/animation.h"
#include "sound.h"

// #include "time/timer.h"
#include "common/files.h"
Expand Down Expand Up @@ -107,8 +108,7 @@ void IRQ::vBlank()
#endif

gdi().present(GE_SUB);
}

}
animationManager().update();

// if( REG_ROMCTRL & CARD_BUSY )
Expand Down
7 changes: 3 additions & 4 deletions romsel_aktheme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ int main(int argc, char **argv)
sfn().initFilenames();
nocashMessage("sfn init");
irq().init();

gdi().init();
// init graphics
gdi().initBg(SFN_LOWER_SCREEN_BG);
Expand Down Expand Up @@ -237,17 +236,17 @@ int main(int argc, char **argv)

//if (!wnd->_mainList->enterDir(SPATH_ROOT != lastDirectory ? lastDirectory : gs().startupFolder))
wnd->_mainList->enterDir(ms().romfolder[ms().secondaryDevice]);

irq().vblankStart();
snd().beginStream();
irq().vblankStart();
while (1)
{
// snd().updateStream();
timer().updateFps();
INPUT &inputs = updateInput();
processInput(inputs);
snd().updateStream();
swiWaitForVBlank();
windowManager().update();
snd().updateStream();
gdi().present(GE_MAIN);
}
return 0;
Expand Down
30 changes: 14 additions & 16 deletions romsel_aktheme/arm9/source/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern volatile s16* fill_stream_buf;
extern volatile s32 filled_samples;

extern volatile bool fill_requested;
extern volatile s32 samples_left_until_next_fill;
extern volatile long streamed_samples;
extern volatile s32 streaming_buf_ptr;

#define SAMPLES_USED (STREAMING_BUF_LENGTH - samples_left)
Expand Down Expand Up @@ -76,23 +76,21 @@ SoundControl::SoundControl()
// 255, // volume
// 128, // panning
// };

stream_source = fopen(std::string(SFN_SOUND_BG).c_str(), "rb");

fseek(stream_source, 0, SEEK_SET);
fseek((FILE*)stream_source, 0, SEEK_SET);

stream.sampling_rate = 16000; // 16000Hz
stream.buffer_length = 800; // should be adequate
stream.buffer_length = 400; // should be adequate
stream.callback = on_stream_request;
stream.format = MM_STREAM_16BIT_MONO; // select format
stream.timer = MM_TIMER0; // use timer0
stream.manual = false; // auto filling

// Prep the first section of the stream
fread((void*)play_stream_buf, sizeof(s16), STREAMING_BUF_LENGTH, stream_source);
fread((void*)play_stream_buf, sizeof(s16), STREAMING_BUF_LENGTH, (FILE*)stream_source);

// Fill the next section premptively
fread((void*)fill_stream_buf, sizeof(s16), STREAMING_BUF_LENGTH, stream_source);
fread((void*)fill_stream_buf, sizeof(s16), STREAMING_BUF_LENGTH, (FILE*)stream_source);

}

Expand Down Expand Up @@ -141,34 +139,34 @@ void SoundControl::setStreamDelay(u32 delay) {
// filled_samples <= streaming_buf_ptr
// fill_requested == false
volatile void SoundControl::updateStream() {

if (!stream_is_playing) return;
if (fill_requested && filled_samples < STREAMING_BUF_LENGTH) {

// Reset the fill request
fill_requested = false;
int instance_filled = 0;

// Either fill the max amount, or fill up the buffer as much as possible.
int instance_to_fill = std::min(SAMPLES_LEFT_TO_FILL, SAMPLES_TO_FILL);
int instance_to_fill = streamed_samples;
streamed_samples = 0;

// If we don't read enough samples, loop from the beginning of the file.
instance_filled = fread((s16*)fill_stream_buf + filled_samples, sizeof(s16), instance_to_fill, stream_source);
instance_filled = fread((s16*)fill_stream_buf + filled_samples, sizeof(s16), instance_to_fill, (FILE*)stream_source);


if (instance_filled < instance_to_fill) {
fseek(stream_source, 0, SEEK_SET);
fseek((FILE*)stream_source, 0, SEEK_SET);
instance_filled += fread((s16*)fill_stream_buf + filled_samples + instance_filled,
sizeof(s16), (instance_to_fill - instance_filled), stream_source);
sizeof(s16), (instance_to_fill - instance_filled), (FILE*)stream_source);
}


#ifdef SOUND_DEBUG
sprintf(debug_buf, "FC: SAMPLES_LEFT_TO_FILL: %li, SAMPLES_TO_FILL: %li, instance_filled: %i, filled_samples %li, to_fill: %i", SAMPLES_LEFT_TO_FILL, SAMPLES_TO_FILL, instance_filled, filled_samples, instance_to_fill);
nocashMessage(debug_buf);
#endif

// maintain invariant 0 < filled_samples <= STREAMING_BUF_LENGTH
filled_samples = std::min<s32>(filled_samples + instance_filled, STREAMING_BUF_LENGTH);


filled_samples = std::min<s32>(filled_samples + instance_filled, STREAMING_BUF_LENGTH);
} else if (fill_requested && filled_samples >= STREAMING_BUF_LENGTH) {
// filled_samples == STREAMING_BUF_LENGTH is the only possible case
// but we'll keep it at gte to be safe.
Expand Down
4 changes: 2 additions & 2 deletions romsel_aktheme/arm9/source/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class SoundControl {
private:
mm_stream stream;
mm_ds_system sys;
bool stream_is_playing;
volatile bool stream_is_playing;
//mm_sound_effect snd_loading;
mm_sound_effect mus_startup;
FILE* stream_source;
volatile FILE* stream_source;
u32 startup_sample_length;
};

Expand Down
5 changes: 4 additions & 1 deletion romsel_aktheme/arm9/source/streamingaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static volatile s16 streaming_buf_swap[STREAMING_BUF_LENGTH] = {0};
*/
volatile s32 streaming_buf_ptr = 0;

volatile long streamed_samples = 0;

/**
* Number of samples filled so far
*/
Expand Down Expand Up @@ -115,6 +117,7 @@ mm_word on_stream_request(mm_word length, mm_addr dest, mm_stream_formats format
// Increment the streaming buf pointer.
streaming_buf_ptr++;

streamed_samples++;
}

if (!sample_delay_count && fade_out && (fade_counter > 0)) {
Expand All @@ -131,7 +134,7 @@ mm_word on_stream_request(mm_word length, mm_addr dest, mm_stream_formats format
// Request a new fill from sound.cpp, refreshing the fill buffer.
// Ensure that fills are requested only if the streaming buf ptr is more than
// the filled samples.
if (!fill_requested && abs(streaming_buf_ptr - filled_samples) >= SAMPLES_PER_FILL) {
if (!fill_requested && streamed_samples >= SAMPLES_PER_FILL) {
#ifdef SOUND_DEBUG
nocashMessage("Fill requested!");
#endif
Expand Down
13 changes: 0 additions & 13 deletions romsel_aktheme/arm9/source/time/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ double Timer::getTime()
return _currentTime;
}

vu64 Timer::getTick()
{
irqDisable( IRQ_TIMER0 );
DC_FlushAll();
static vu64 lastTick = 0;
vu64 tick = _overFlow + TIMER0_DATA;
if( tick < lastTick )
tick += 65536;
lastTick = tick;
irqEnable( IRQ_TIMER0 );
return tick;
}

double Timer::tickToUs( u64 tick )
{
return tick * 1.f/(33.514*1000000.f) * 1000 * 1000;
Expand Down
2 changes: 0 additions & 2 deletions romsel_aktheme/arm9/source/time/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class Timer

double getTime();

vu64 getTick();

double tickToUs(u64 tick);

private:
Expand Down
4 changes: 4 additions & 0 deletions romsel_aktheme/arm9/source/ui/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "time/timer.h"
#include "tool/dbgtool.h"
#include "windowmanager.h"
#include "sound.h"

namespace akui
{
Expand Down Expand Up @@ -216,11 +217,14 @@ u32 Form::doModal()

do
{ // manually update system loop
// snd().updateStream();
timer().updateFps();
INPUT &inputs = updateInput();
processInput(inputs);
windowManager().update();
// snd().updateStream();
gdi().present(GE_MAIN);

//dbg_printf( "modal window looping\n" );
} while (modalRet() == (u32)-1);

Expand Down
6 changes: 3 additions & 3 deletions romsel_aktheme/compile_docker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ if (!$?) {
}

#check for TWiLightMenu image
docker image inspect TWiLightMenu >$null 2>&1
docker image inspect twilightmenu >$null 2>&1

if (!$?) {
# build the image if it doesn't exist.
docker build -t TWiLightMenu --label TWiLightMenu ../
docker build -t twilightmenu --label TWiLightMenu ../
}

docker run --rm -t -i -v "$pwd\:/data" TWiLightMenu make @args
docker run --rm -t -i -v "$pwd/../:/data" -w "/data/romsel_aktheme" TWiLightMenu make @args

if($args.Count -eq 0 -and $?) {
Copy-Item "romsel_aktheme.nds" "../7zfile/_nds/TWiLightMenu/akmenu.srldr"
Expand Down
Binary file added romsel_dsimenutheme/nitrofiles/sound/bgm.pcm.raw
Binary file not shown.

0 comments on commit b16cb1c

Please sign in to comment.