Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

We are doing a game in XNA that reacts to music. We need to do some offline processing of the music data and therefore we need a custom type containing the Song and some additional data:

// Project AudioGameLibrary
namespace AudioGameLibrary
{
    public class GameTrack
    {
        public Song Song;
        public string Extra;
    }
}

We've added a Content Pipeline extension:

// Project GameTrackProcessor
namespace GameTrackProcessor
{
    [ContentSerializerRuntimeType("AudioGameLibrary.GameTrack, AudioGameLibrary")]
    public class GameTrackContent
    {
        public SongContent SongContent;

        public string Extra;
    }

    [ContentProcessor(DisplayName = "GameTrack Processor")]
    public class GameTrackProcessor : ContentProcessor<AudioContent, GameTrackContent>
    {
        public GameTrackProcessor(){}

        public override GameTrackContent Process(AudioContent input, ContentProcessorContext context)
        {

            return new GameTrackContent() 
            { 
                SongContent = new SongProcessor().Process(input, context),
                Extra = "Some extra data" // Here we can do our processing on 'input'
            };
        }
    }
}

Both the Library and the Pipeline extension are added to the Game Solution and references are also added. When trying to use this extension to load "gametrack.mp3" we run into problems however:

// Project AudioGame
protected override void LoadContent()
{
    AudioGameLibrary.GameTrack gameTrack = Content.Load<AudioGameLibrary.GameTrack>("gametrack");

    MediaPlayer.Play(gameTrack.Song);
}

The error message:

Error loading "gametrack". File contains Microsoft.Xna.Framework.Media.Song but trying to load as AudioGameLibrary.GameTrack.

AudioGame contains references to both AudioGameLibrary and GameTrackProcessor. Are we maybe missing other references?

EDIT

Selecting the correct content processor helped, it loads the audio file correctly. However, when I try to process some data, e.g:

public override GameTrackContent Process(AudioContent input, ContentProcessorContext context)
{
    int count = input.Data.Count; // With this commented out it works fine

    return new GameTrackContent() 
    { 
        SongContent = new SongProcessor().Process(input, context)
    };
}

It crashes with the following error:

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\Maarten\Documents\Visual Studio 2010\Projects\AudioGame\DebugPipeline\bin\Debug\DebugPipeline.exe'.
Additional Information: A call to PInvoke function 'Microsoft.Xna.Framework.Content.Pipeline!Microsoft.Xna.Framework.Content.Pipeline.UnsafeNativeMethods+AudioHelper::OpenAudioFile' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Information from logger right before crash:

  Using "BuildContent" task from assembly "Microsoft.Xna.Framework.Content.Pipel
ine, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553".
  Task "BuildContent"
    Building gametrack.mp3 -> bin\x86\Debug\Content\gametrack.xnb
    Rebuilding because asset is new
    Importing gametrack.mp3 with Microsoft.Xna.Framework.Content.Pipeline.Mp3Imp
orter

Im experiencing exactly this: http://forums.create.msdn.com/forums/t/75996.aspx

EDIT2

The second problem was fixed by using SoundEffect instead of Song inside the GameTrack struct and using an uncompressed audio format (WAV). It turns out that accessing AudioContent.Data is not supported for compressed formats.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

You have to change the "Content Processor" property of your gametrack.mp3 file to match the name of your custom Content Processor. This is done in the "Properties" window of Visual Studio.

share|improve this answer
    
Thanks, that is at least one step I forgot. I've updated the question with a new error. –  Maarten Mar 29 '12 at 23:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.