• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Optimisation of my audio player application (Mac)

0 posts in this topic

I am working on an audio player application for Mac, and have made a play routine for both wav and flac files from scratch, and will soon start working on a mp3 decoder too.  While this is working great, I am trying to squeeze as much fast response and performance as I can out of the application.


My goal is to make a super responsive audio player that later will be part of an (semi) automated audio transcription tool.


Now I am looking to optimise my audio player before I move on to add more functionality.


My first optimisation was a qualified guess:


I have a bit file reader that I have made, that I just threw together to be able to read a file on a number of bit basis.  This actually would just read one and one byte from the file and shift the data into the integer type I wanted, bit by bit.


The optimisation I did, was to create a double buffer and pre-read an amount of data to that buffer instead of requesting one and one byte from the file like I did in the version I just threw together.  The reason I made the buffer "double buffering" is that I thought that I would always have one buffer ready, and that I could increase responsiveness by reading data into the used buffer from another thread.  I am not sure if this really is a good idea, but I will test this later.  Now I just have prepared so it will be trivial to add this functionality.


This initial optimisation made the CPU usage drop from about 30% down to about 6%.  I'd say that is a good improvement.


Now I want to try to reduce the CPU Energy Impact to land in the "low" area instead of constantly "high".  I am wondering if this is at all possible in an application like this, where there are constant reads from disk and Audio Queues constantly requesting more data to play, and also graphics that is updated on regular basis.  (Probably not more than 4 times per second, but still...)


I also notice something called 'wakes' per second.  This number varies between 4 and 11, but is mostly residing at 4.  I don't really know what kind of an impact this has on my application, and I am not even sure I can avoid it to happen.  I am thinking that maybe I can reduce the wakes to happen in "bulk" somehow, but I need to learn more about this topic.  It is hard to find any good information on this.


I also wonder how you might go about trying to reduce the energy impact in such an application where you constantly stream audio from file to an audio device.


Lastly, a weird bug that I am not even sure what is caused by.  Sometimes I have a drop-out in the audio.  It is not a long dropout, and the progress bar is moving and it seems that the song is playing, but there is no sound for the short duration of the dropout.  The stream is not reporting any errors, and I have the same problem wether I play wav or flac.  Both play routines are written independently of each other and from scratch, and with TONS of sanity and error checking, and buffer overflow protection, that I would see if the play routines did something weird.  I am suspecting latency in the system, but I have no idea how to pursue that.  I was hoping that buffering the bit file reader would solve the problem, and sort of it did - the short drop-outs are a bit shorter now...  When the audio comes back, it indeed did play with no sound, since the song does not resume from where it stopped.  To combat this, I have tried to increase buffer sizes.  The dropouts are still of the same length.  It really seems to be relating to some issue with how the system either manages sleep on the hard drive OR how the system accumulates threading by delaying threads a little bit to reduce the energy impact.  Yes, OS X does this to some extent, but I don't know how to even start to debug this problem.


I have one idea I am planning to try, though...  To try to time different sections of the code to see if there is any major deviations when this happens.


I am happy for any feedback or suggestions.  Thank you! smile.png



EDIT 2014 06 10:


Instead of waking this old thread, I will just make an edit: 


I found a likely reason for why I am getting audio drop-outs.  It is called App Nap on OS X Mavericks.  It is not supposed to affect apps that is playing audio, but I see that it is an issue with Mavericks:




I also see similar behaviour in other apps that I never had problems with before Mavericks.

Edited by aregee

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0