Comments (8)
With the changes currently pending merge to address the sample rate change issues I've also now included a uint8_t * SplitterChannel::pullInto( uint8_t * rawBuffer, int length )
method as part of the SplitterChannel.
This lets you supply an arbitrary block of data, and have the benefits of automatic resampling along with keeping the 'contract' between stream classes to keep the microphone auto-wake functions working. The return pointer is set to the next byte in memory if you're using a large buffer with multiple samples stored sequentially, so by tracking the return between calls you can automatically wander the larger buffer.
If the supplied memory is smaller than required, it will be completely filled and the data will be truncated; if the memory is longer than required, the complete upstream buffer will be copied in and the rest of the memory will be untouched.
Thanks for everyone's patience on this issue, its hit quite a few things at once :)
from codal-microbit-v2.
I think this is a pretty good suggestion for cases where 'userland' runtimes want more direct C-alike access to memory from a stream. To this end, I plan to roll this in with the changes required to support/fix #394 and #321 and squash all three bugs at once.
Unfortunately I'm on leave for the next week, and will be back in the office on Monday 27th, so I'll pick this up then as a priority.
from codal-microbit-v2.
from codal-microbit-v2.
Note: Using this issue to track the discussion for implementation to address all the linked issues here.
from codal-microbit-v2.
if the memory is longer than required, the complete upstream buffer will be copied in and the rest of the memory will be untouched.
Testing out this new pullInto()
method, I'm not sure the above behaviour is implemented correctly. Passing in a large buffer, it seems to just keep on sampling the input buffer past its end, and only stops once it has filled the given output buffer. This means that you have to request exactly the number of bytes that are available, and it's not really possible to know this.
In the code you can see that the loop to copy the samples from input to output uses while( outPtr - output < length )
, and if a buffer is passed in then length
is just taken as the passed-in length. The following patch gets it working for me:
--- a/source/streams/StreamSplitter.cpp
+++ b/source/streams/StreamSplitter.cpp
@@ -74,6 +74,10 @@ ManagedBuffer SplitterChannel::resample( ManagedBuffer _in, uint8_t * buffer, in
if( output == NULL ) {
output = (uint8_t *)malloc( samplesPerOut * bytesPerSample );
length = samplesPerOut * bytesPerSample;
+ } else {
+ if (length > samplesPerOut * bytesPerSample) {
+ length = samplesPerOut * bytesPerSample;
+ }
}
int oversample_offset = 0;
from codal-microbit-v2.
Testing out this new pullInto() method, I'm not sure the above behaviour is implemented correctly. Passing in a large buffer, it seems to just keep on sampling the input buffer past its end, and only stops once it has filled the given output buffer.
Ah! Good catch! The pullInto()
method was less completely tested (I don't have a use case for this inside CODAL itself) so I missed that one. I'll merge your proposed patch into master
and can you let me know if everything then works with Python when built against it all? If so, we'll call this the next minor rev with a couple of other smaller merges.
from codal-microbit-v2.
Aaand patched, pushed, tagged and released. Might as well get this out the door ASAP so you have everything you need for Python @dpgeorge 👍
For ref: https://github.com/lancaster-university/codal-microbit-v2/releases/tag/v0.2.66
from codal-microbit-v2.
Thanks for the quick patch and release! I have tested it and it works. I have updated all our code to use the new v0.2.66 release.
from codal-microbit-v2.
Related Issues (20)
- `wasPressed()` for the `TouchButton` class HOT 4
- Waking up turns on the microphone even if it is never used HOT 2
- Should fibers wait for access to serial?
- Set audio pin creates a 44.2kHz 50% PWM after audio playback HOT 2
- MicroBitButton.h missing in MicroBit.h when DEVICE_BLE=0 HOT 6
- Snapshot v0.2.63 points to a codal-microbit-nrf5sdk commit that is not in the repo HOT 1
- In a tight loop, mostly deep sleeping, takes 600 milliseconds to go back to sleep HOT 1
- Data log "full" marker is not being written to interface storage HOT 7
- MakeCode `randint()` not random when Bluetooth enabled HOT 1
- Default `uBit.io.logo` touch type should be capacitive. HOT 3
- A way to configure a pin on open drain mode HOT 1
- Overloaded virtual warnings
- Quickly switching between resistive and capacitive pin touch and checking state doesn't work
- `NRF52Pin::wasTouched()` default mode is capacitative instead of the pin state HOT 1
- Are all `time.tick_xxx()` functions bound to 30 bits? HOT 2
- Counting CPU cycles with `DWT->CTRL` does not match expectations HOT 2
- For characters not in the font, display scrolls a null pointer HOT 2
- Should the display be cleared when trying to print an invalid character?
- Should scrolling/printing out-of-range characters on the display be an "error glyph" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codal-microbit-v2.