Skip to content

Commit

Permalink
properly fix all aplay RT stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
PoroCYon committed Aug 31, 2020
1 parent 7930f08 commit c74d60e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions WaveSabreCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ if(MSVC)
else()
# assuming GCC or clang for now

#set(CMAKE_CXX_FLAGS "-g -Og")
set(CMAKE_CXX_FLAGS "-g -Og")
# stuff to make the code smaller
set_property(TARGET WaveSabreCore PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
#set_property(TARGET WaveSabreCore PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
#set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
endif()
6 changes: 3 additions & 3 deletions WaveSabrePlayerLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ if(MSVC)
else()
# assuming GCC or clang for now

#set(CMAKE_CXX_FLAGS "-g -Og")
set(CMAKE_CXX_FLAGS "-g -Og")
# stuff to make the code smaller
set_property(TARGET WaveSabrePlayerLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
#set_property(TARGET WaveSabrePlayerLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
#set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace WaveSabrePlayerLib
int sampleRate;
int bufferSizeMs;
int bufferSizeBytes;
int samplesWritten;
int bytesWritten;
SongRenderer::Sample *sampleBuffer;
const SongRenderer::Sample *bufferToWrite;
size_t bufferBytesLeft;
Expand Down
9 changes: 5 additions & 4 deletions WaveSabrePlayerLib/src/AplayRenderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace WaveSabrePlayerLib
, callbackData(callbackData)
, sampleRate(sampleRate)
, bufferSizeMs(bufferSizeMs)
, samplesWritten(0)
, bytesWritten(0)
, bufferBytesLeft(0)
, writeBytesMax(PIPE_BUF)
#if HAVE_PTHREAD
Expand All @@ -45,7 +45,8 @@ namespace WaveSabrePlayerLib
#endif

bufferSizeBytes = sampleRate * SongRenderer::BlockAlign * bufferSizeMs / 1000;
bufferToWrite = (SongRenderer::Sample*)malloc(bufferSizeBytes);
sampleBuffer = (SongRenderer::Sample*)malloc(bufferSizeBytes);
bufferToWrite = sampleBuffer;

int fdpair[2];
int rv = pipe(fdpair);
Expand Down Expand Up @@ -141,7 +142,7 @@ namespace WaveSabrePlayerLib

int AplayRenderThread::GetPlayPositionMs()
{
return (samplesWritten * 1000) / sampleRate;
return (int)(bytesWritten / SongRenderer::BlockAlign * 1000 / sampleRate);
}

void AplayRenderThread::AplayProc(int readend, int rate)
Expand Down Expand Up @@ -222,7 +223,7 @@ namespace WaveSabrePlayerLib
//printf("written buffer %p size 0x%zx, wrote 0x%zx bytes, left: 0x%zx\n",
// bufferToWrite, toWrite, (size_t)ret, bufferBytesLeft);
bufferToWrite += ret / sizeof(SongRenderer::Sample);
samplesWritten += ret / sizeof(SongRenderer::Sample);
bytesWritten += ret;

break;
}
Expand Down
6 changes: 3 additions & 3 deletions WaveSabreStandAlonePlayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if(MSVC)
else()
# assuming GCC or clang for now

#set(CMAKE_CXX_FLAGS "-g -Og")
set(CMAKE_CXX_FLAGS "-g -Og")
# stuff to make the code smaller
set_property(TARGET WaveSabrePlayerLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
#set_property(TARGET WaveSabrePlayerLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True) # enable LTO
#set(CMAKE_CXX_FLAGS "-g -O2 -ffast-math -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections")
endif()
7 changes: 4 additions & 3 deletions WaveSabreStandAlonePlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ int main(int argc, char **argv)
"Writing WAV instead...\n");
writeWav = true;
}*/
writeWav = true;
preRender = true;
//writeWav = true;
//preRender = true;
#endif

#if defined(WIN32) || defined(_WIN32)
const int numRenderThreads = 3;
#else
const int numRenderThreads = 3; // TODO
const int numRenderThreads = 3;
#endif

FILE * pFile;
Expand Down Expand Up @@ -182,6 +182,7 @@ int main(int argc, char **argv)
#if defined(WIN32) || defined(_WIN32)
Sleep(10);
#else
fflush(stdout);
sleep( 1);
#endif
}
Expand Down

0 comments on commit c74d60e

Please sign in to comment.