MCPcopy Create free account
hub / github.com/DISTRHO/DPF / pullBuffer

Method pullBuffer

distrho/src/jackbridge/rtaudio/RtAudio.cpp:3922–3981  ·  view source on GitHub ↗

attempt to pull a buffer from the ring buffer from the current "out" index

Source from the content-addressed store, hash-verified

3920
3921 // attempt to pull a buffer from the ring buffer from the current "out" index
3922 bool pullBuffer( char* buffer, unsigned int bufferSize, RtAudioFormat format )
3923 {
3924 if ( !buffer || // incoming buffer is NULL
3925 bufferSize == 0 || // incoming buffer has no data
3926 bufferSize > bufferSize_ ) // incoming buffer too large
3927 {
3928 return false;
3929 }
3930
3931 unsigned int relInIndex = inIndex_;
3932 unsigned int outIndexEnd = outIndex_ + bufferSize;
3933 if ( relInIndex < outIndex_ && outIndexEnd >= bufferSize_ ) {
3934 relInIndex += bufferSize_;
3935 }
3936
3937 // the "OUT" index CANNOT BEGIN at the "IN" index
3938 // the "OUT" index CAN END at the "IN" index
3939 if ( outIndex_ <= relInIndex && outIndexEnd > relInIndex ) {
3940 return false; // not enough space between "out" index and "in" index
3941 }
3942
3943 // copy buffer from internal to external
3944 int fromZeroSize = outIndex_ + bufferSize - bufferSize_;
3945 fromZeroSize = fromZeroSize < 0 ? 0 : fromZeroSize;
3946 int fromOutSize = bufferSize - fromZeroSize;
3947
3948 switch( format )
3949 {
3950 case RTAUDIO_SINT8:
3951 memcpy( buffer, &( ( char* ) buffer_ )[outIndex_], fromOutSize * sizeof( char ) );
3952 memcpy( &( ( char* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( char ) );
3953 break;
3954 case RTAUDIO_SINT16:
3955 memcpy( buffer, &( ( short* ) buffer_ )[outIndex_], fromOutSize * sizeof( short ) );
3956 memcpy( &( ( short* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( short ) );
3957 break;
3958 case RTAUDIO_SINT24:
3959 memcpy( buffer, &( ( S24* ) buffer_ )[outIndex_], fromOutSize * sizeof( S24 ) );
3960 memcpy( &( ( S24* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( S24 ) );
3961 break;
3962 case RTAUDIO_SINT32:
3963 memcpy( buffer, &( ( int* ) buffer_ )[outIndex_], fromOutSize * sizeof( int ) );
3964 memcpy( &( ( int* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( int ) );
3965 break;
3966 case RTAUDIO_FLOAT32:
3967 memcpy( buffer, &( ( float* ) buffer_ )[outIndex_], fromOutSize * sizeof( float ) );
3968 memcpy( &( ( float* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( float ) );
3969 break;
3970 case RTAUDIO_FLOAT64:
3971 memcpy( buffer, &( ( double* ) buffer_ )[outIndex_], fromOutSize * sizeof( double ) );
3972 memcpy( &( ( double* ) buffer )[fromOutSize], buffer_, fromZeroSize * sizeof( double ) );
3973 break;
3974 }
3975
3976 // update "out" index
3977 outIndex_ += bufferSize;
3978 outIndex_ %= bufferSize_;
3979

Callers 1

wasapiThreadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected