1

I use DynamicSoundEffectInstance in an Xbox 360 project.

The problem is that the buffercount grows really fast until it reaches 64 and the app crasches. As far as I can see it shouldn't grow at all?

To test I have over simplified the code to go back to the basics.

Here is some of the code (the rest in the project is untouched from the template)

    DynamicSoundEffectInstance soundEffect = new DynamicSoundEffectInstance(22500, AudioChannels.Mono);
    int bufferCount=0;
    byte[] BufferHigh;
    byte[] BufferLow;
    bool alternate = true;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        this.IsFixedTimeStep = true;
        this.TargetElapsedTime = TimeSpan.FromMilliseconds(20);
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        bufferCount = soundEffect.GetSampleSizeInBytes(new TimeSpan(0, 0, 0, 0, 20));
        BufferHigh = Enumerable.Repeat<byte>((byte)255, bufferCount).ToArray();
        BufferLow = Enumerable.Repeat<byte>((byte)127, bufferCount).ToArray();
        soundEffect.Play();
    }

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        if (alternate)
            soundEffect.SubmitBuffer(BufferHigh);
        else
            soundEffect.SubmitBuffer(BufferLow);

        alternate = !alternate;

        Debug.WriteLine("elapsed: " + gameTime.ElapsedGameTime.TotalMilliseconds);  
        Debug.WriteLine("buffercount: " +soundEffect.PendingBufferCount);

        base.Update(gameTime);
    }

The code should alternate between high and low creating a clicking sound. Any suggestions? The same code works great on a Windows Phone

Skami
  • 1,506
  • 1
  • 18
  • 29
Jimmy Engtröm
  • 1,998
  • 4
  • 23
  • 34

0 Answers0