Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:30:56+00:00 2026-06-02T03:30:56+00:00

This is a .NET wrapper for the library Secret Rabbit Code (aka libsamplerate) ,

  • 0

This is a .NET wrapper for the library Secret Rabbit Code (aka libsamplerate), when calling src_callback_read in CallbackRead : AccessViolationException – Attempted to read or write protected memory.

From C header :

/* Opaque data type SRC_STATE. */
typedef struct SRC_STATE_tag SRC_STATE ;

typedef long (*src_callback_t) (void *cb_data, float **data) ;

SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,                 int *error, void* cb_data) ;

long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *

I then created the following :

C++/CLI class library that calls the C library :

public delegate long SRCCallback ( void *cb_data, float **data ) ;

static  IntPtr CallbackNew ( SRCCallback ^func, RabbitConverter converter_type, int channels, int *error, void* cb_data )
        {
            src_callback_t* cb = ( src_callback_t* ) &func;
            SRC_STATE* state =  src_callback_new ( *cb, ( int ) converter_type, channels, error, cb_data );
            IntPtr ptr = IntPtr ( state );
            return ptr;
        }

static long CallbackRead ( IntPtr  src_state, double src_ratio, long frames , float * data )
        {
            void* toPointer = src_state.ToPointer();
            SRC_STATE* state = ( SRC_STATE* ) toPointer;
            long l = src_callback_read ( state, src_ratio, frames, data );
            return l;
        }

C# application that uses the C++/CLI library :

private static readonly unsafe SRCCallback _callback = target;

private static unsafe void Callback()
{
    var input = GetSine(1000.0d, 44100, 1);
    fixed (float* f = input)
    {
        RabbitError error = RabbitError.SRC_ERR_NO_ERROR;
        var @void = Rabbit.CallbackNew(_callback, RabbitConverter.SRC_SINC_BEST_QUALITY, 1, (int*) (&error),
                                        (void*) IntPtr.Zero);
        var callbackRead = Rabbit.CallbackRead(@void  , 1d, input.Length/2, f);
        if (callbackRead != input.Length)
        {
            // throw new InvalidOperationException();
        }
    }
}

private static unsafe int target(void* cb_data, float** data)
{
    return 9;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:30:58+00:00Added an answer on June 2, 2026 at 3:30 am

    I have fixed it using the following :

    [System::Runtime::InteropServices::UnmanagedFunctionPointerAttribute ( CallingConvention::Cdecl )]
    public delegate long SRCCallback ( void *cb_data, float **data ) ;
    
    static  IntPtr CallbackNew ( SRCCallback ^ % func, RabbitConverter converter_type, int channels, int *error, void* cb_data ) { ... }
    

    In short : now it uses C calling convention and C# ref keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this VB.NET code: Dim o as SomeClass Try o = new SomeClass 'call
I have a native C++ library with a .NET wrapper, all built in Visual
I've got some library code that works on a range of .NET runtimes (regular,
I'm looking for a .NET library or wrapper for Google Maps, that contains all
We've written a .NET wrapper API for a set of web services. All this
This .NET API works OK if I'm trying to open the Registry in a
I have compiled a .NET application using Any CPU option. This .NET application uses
This question is similar to this: Asp.net Profile Across Sub-Domain I'm basically wondering if
In this asp.net page, there is a link that leads to another page in
We're developing this ASP.NET web app with multiple users on different browsers. One of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.