Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Last active September 12, 2023 14:46
Show Gist options
  • Save atsushieno/47bbbd40bdddb2e322ef77109966ad71 to your computer and use it in GitHub Desktop.
Save atsushieno/47bbbd40bdddb2e322ef77109966ad71 to your computer and use it in GitHub Desktop.
diff --git a/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.Plugin.cpp b/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.Plugin.cpp
index 8ca8c5b8..cbc65745 100644
--- a/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.Plugin.cpp
+++ b/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.Plugin.cpp
@@ -10,6 +10,8 @@ bool aap::AudioPluginNode::shouldSkip() {
return plugin == nullptr;
}
+int32_t checkedValidEmptyBuffers{0};
+int32_t checkedAudioProcessing{0};
void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrames) {
if (!plugin)
return;
@@ -21,6 +23,7 @@ void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrame
auto aapBuffer = plugin->getAudioPluginBuffer();
int32_t currentChannelInAudioData = 0;
+ bool wasNotEmpty = false;
for (int32_t i = 0, n = aapBuffer->num_ports(*aapBuffer); i < n; i++) {
if (plugin->getPort(i)->getPortDirection() != AAP_PORT_DIRECTION_INPUT)
continue;
@@ -29,6 +32,7 @@ void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrame
memcpy(aapBuffer->get_buffer(*aapBuffer, i),
audioData->audio.getView().getChannel(currentChannelInAudioData).data.data,
numFrames * sizeof(float));
+ wasNotEmpty |= !choc::buffer::isAllZero(audioData->audio.getView().getChannel(currentChannelInAudioData));
currentChannelInAudioData++;
break;
case AAP_CONTENT_TYPE_MIDI2: {
@@ -42,6 +46,8 @@ void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrame
break;
}
}
+ //if (wasNotEmpty)
+ // aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!Plugin", "Plugin INPUT is not empty.");
plugin->process(numFrames, 0); // FIXME: timeout?
@@ -54,6 +60,7 @@ void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrame
memcpy(audioData->audio.getView().getChannel(currentChannelInAudioData).data.data,
aapBuffer->get_buffer(*aapBuffer, i),
numFrames * sizeof(float));
+ assert(!wasNotEmpty || !choc::buffer::isAllZero(audioData->audio.getView().getChannel(currentChannelInAudioData)));
currentChannelInAudioData++;
break;
case AAP_CONTENT_TYPE_MIDI2: {
@@ -66,6 +73,24 @@ void aap::AudioPluginNode::processAudio(AudioBuffer *audioData, int32_t numFrame
break;
}
}
+ /*
+ if (wasNotEmpty)
+ aap::a_log_f(AAP_LOG_LEVEL_INFO, AAP_MANAGER_LOG_TAG, "Audio buffer is not empty.");
+ if (wasNotEmpty) {
+ checkedAudioProcessing++;
+ if (checkedAudioProcessing > 100) {
+ aap::a_log_f(AAP_LOG_LEVEL_INFO, AAP_MANAGER_LOG_TAG,
+ "Audio buffer is successfully non-empty.");
+ checkedAudioProcessing = -0x7FFFFFFF;
+ }
+ } else {
+ checkedValidEmptyBuffers++;
+ if (checkedValidEmptyBuffers > 100) {
+ aap::a_log_f(AAP_LOG_LEVEL_INFO, AAP_MANAGER_LOG_TAG,
+ "Audio buffer is successfully empty.");
+ checkedValidEmptyBuffers = -0x7FFFFFFF;
+ }
+ }*/
}
void aap::AudioPluginNode::start() {
diff --git a/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.cpp b/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.cpp
index 404a59b9..d4892e5c 100644
--- a/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.cpp
+++ b/androidaudioplugin-manager/src/main/cpp/AudioGraphNode.cpp
@@ -6,6 +6,8 @@
#include <audio/choc_AudioFileFormat_FLAC.h>
#include <audio/choc_SincInterpolator.h>
+#define LOG_TAG "AAP.AudioGraph"
+
aap::AudioDeviceInputNode::~AudioDeviceInputNode() {
getDevice()->stopCallback();
}
@@ -70,6 +72,8 @@ public:
case std::ios_base::cur: gbump((int) off); break;
case std::ios_base::end: setg(eback(), egptr() + off, egptr()); break;
}
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "SeekableByteBuffer", "SeekableByteBuffer seekoff(%d, %d, %d) -> %d",
+ off, dir, which, gptr() - eback());
return gptr() - eback();
}
};
@@ -111,22 +115,36 @@ int32_t aap::AudioDataSourceNode::read(AudioBuffer *dst, int32_t numFrames) {
if (size <= 0)
return 0;
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, LOG_TAG, "read() %d %d %d",
+ audio_data->audio.getNumFrames(), current_frame_offset, numFrames);
if (shouldConsumeButBypass()) {
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, LOG_TAG, "shouldConsumeButBypass().");
current_frame_offset += size;
return size;
}
// read only if it is not locked.
if (std::unique_lock<NanoSleepLock> tryLock(data_source_mutex, std::try_to_lock); tryLock.owns_lock()) {
+ //if (current_frame_offset == 0)
+ // aap::a_log_f(AAP_LOG_LEVEL_DEBUG, LOG_TAG, "Started reading audio data source, looking all good.");
choc::buffer::FrameRange range{(uint32_t) current_frame_offset, current_frame_offset + size};
choc::buffer::copyRemappingChannels(dst->audio.getStart(size),
audio_data->audio.getFrameRange(range));
+ /*
+ if (current_frame_offset == 0 && !choc::buffer::isAllZero(audio_data->audio))
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!AudioDataSource", "read() input is not empty.");
+ if (current_frame_offset == 0 && !choc::buffer::isAllZero(dst->audio))
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!AudioDataSource", "read() output is not empty.");
+ */
current_frame_offset += size;
return size;
}
- else
+ else {
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, LOG_TAG,
+ "Failed to acquire NanoSleepLock.");
return 0;
+ }
}
choc::audio::WAVAudioFileFormat<false> formatWav{};
@@ -138,6 +156,11 @@ choc::audio::AudioFileFormat* formats[] {&formatWav, &formatMp3, &formatOgg, &fo
bool aap::AudioDataSourceNode::setAudioSource(uint8_t *data, int dataLength, const char *filename) {
const std::lock_guard <NanoSleepLock> lock{data_source_mutex};
+ uint8_t zzz[4096];
+ memset(zzz, 0, 4096);
+ for (size_t s = 0; s + 4095 < dataLength; s += 4096)
+ assert(memcmp(zzz, data + s, 4096));
+
for (auto format : formats) {
if (format->filenameSuffixMatches(filename)) {
SeekableByteBuffer buffer(data, dataLength);
@@ -146,6 +169,9 @@ bool aap::AudioDataSourceNode::setAudioSource(uint8_t *data, int dataLength, con
auto props = reader->getProperties();
AudioBuffer tmpData{(int32_t) props.numChannels, (int32_t) props.numFrames};
assert(reader->readFrames(0, tmpData.audio));
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!AudioDataSource", "setAudioSource() tmpData numFrames %d, buffer: %s / %s",
+ tmpData.audio.getNumFrames(),
+ choc::buffer::isAllZero(tmpData.audio) ? "empty!!!" : "non-empty", props.getDescription().c_str());
// resample
auto durationInSeconds = 1.0 * props.numFrames / props.sampleRate;
@@ -153,10 +179,16 @@ bool aap::AudioDataSourceNode::setAudioSource(uint8_t *data, int dataLength, con
audio_data = std::make_unique<AudioBuffer>((int32_t) props.numChannels, targetFrames);
choc::interpolation::sincInterpolate(audio_data->audio, tmpData.audio);
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, LOG_TAG, "Audio file stream %s is loaded", filename);
+ assert(!choc::buffer::isAllZero(audio_data->audio));
+ aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!AudioDataSource", "setAudioSource() audio_data buffer: %s",
+ choc::buffer::isAllZero(audio_data->audio) ? "empty!!!" : "non-empty");
return true;
}
}
+ aap::a_log_f(AAP_LOG_LEVEL_ERROR, LOG_TAG, "Audio file stream %s is not supported", filename);
+
return false;
}
diff --git a/audio/choc_AudioFileFormat_Ogg.h b/audio/choc_AudioFileFormat_Ogg.h
index 9957324..b2e79cd 100644
--- a/audio/choc_AudioFileFormat_Ogg.h
+++ b/audio/choc_AudioFileFormat_Ogg.h
@@ -54972,8 +54972,10 @@ inline int _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
/* only seek if the file position isn't already there */
if(vf->offset != offset){
if(!(vf->callbacks.seek_func)||
- (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1)
+ (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1) {
+aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!choc", "_seek_helper() resulted in OV_EREAD");
return OV_EREAD;
+ }
vf->offset=offset;
ogg_sync_reset(&vf->oy);
}
@@ -59420,6 +59422,8 @@ inline void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
//==============================================================================
//==============================================================================
+#include <aap/unstable/logging.h>
+
template <bool supportWriting>
struct OggAudioFileFormat<supportWriting>::Implementation
{
@@ -59502,6 +59506,7 @@ struct OggAudioFileFormat<supportWriting>::Implementation
{
auto numChannels = buffer.getNumChannels();
+aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!choc", "%d/%d | %d + %d / %d", numChannels, properties.numChannels, frameIndex, buffer.getNumFrames(), properties.numFrames);
if (numChannels != properties.numChannels)
return false;
@@ -59535,6 +59540,7 @@ struct OggAudioFileFormat<supportWriting>::Implementation
}
}
+aap::a_log_f(AAP_LOG_LEVEL_DEBUG, "!!!!!!choc", "FRAMES NOT READ? %d", buffer.getNumFrames());
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment