Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. creating a circular array

creating a circular array

Scheduled Pinned Locked Moved C#
visual-studiodata-structureshelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve1_rm
    wrote on last edited by
    #1

    Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,

    private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
    {
    Int16[] samples = new Int16[8192 / sizeof(Int16)];
    Int16 audioValue = 0;
    int i = 0;
    captureBuff.Start(true);

            while (captureAudio)
            {
                if (!this.bgwAudioInput.CancellationPending)
                {
                    captureBuff.Read(samples, 0, true);
                    audioValue = Math.Abs(samples\[i++\]);
                    this.bgwAudioInput.ReportProgress(audioValue);
                }
            }
    

    }

    A L 2 Replies Last reply
    0
    • S Steve1_rm

      Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,

      private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
      {
      Int16[] samples = new Int16[8192 / sizeof(Int16)];
      Int16 audioValue = 0;
      int i = 0;
      captureBuff.Start(true);

              while (captureAudio)
              {
                  if (!this.bgwAudioInput.CancellationPending)
                  {
                      captureBuff.Read(samples, 0, true);
                      audioValue = Math.Abs(samples\[i++\]);
                      this.bgwAudioInput.ReportProgress(audioValue);
                  }
              }
      

      }

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Hi,

      Steve1_rm wrote:

      The problem I have is that the buffer will overrun

      Are you sure about that? It looks to me as if you are attempting to read beyond the end of the array. Every iteration of the while loop reads data into the samples array. That's ok but eventually the indexer i has the value 4096 and the array access in the line audioValue = Math.Abs(samples[i++]); will fail. I can't understand the meaning of audioValue and how it would relate to progress. Did you mean to report total amount of data read perhaps? Alan.

      1 Reply Last reply
      0
      • S Steve1_rm

        Hello, VS 2008 I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone. The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again? Many thanks for any suggestions,

        private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
        {
        Int16[] samples = new Int16[8192 / sizeof(Int16)];
        Int16 audioValue = 0;
        int i = 0;
        captureBuff.Start(true);

                while (captureAudio)
                {
                    if (!this.bgwAudioInput.CancellationPending)
                    {
                        captureBuff.Read(samples, 0, true);
                        audioValue = Math.Abs(samples\[i++\]);
                        this.bgwAudioInput.ReportProgress(audioValue);
                    }
                }
        

        }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Steve1_rm wrote:

        It there anyway to create a circuler buffer that once it gets to the the end it will start over again?

        Sure, just index with i%length or i&(length-1) for powers of 2 (which you have here)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups