There's also live online events, interactive content, certification prep materials, and more. Reimagined for full-screen and touch-optimized apps, Windows 8 provides a platform for reaching new users in new ways. In response, programming legend Charles Petzold is rewriting his classic Programming Windows—one of the most popular programming books of all time—to show developers how to use existing skills and tools to build Windows 8 apps.
The Sixth Edition is organized in two parts:. You should emerge from Part I ready to create sophisticated page-oriented collection-based user interfaces using the powerful ListView and GridView controls.
A frequency of Hz is the A above middle C and is used as a tuning standard. I was particularly intrigued by this latter method, because it seemed to provide a way to create an oscillator that generates a particular periodic waveform at a variable frequency with a minimum of fuss.
Figure 1 shows the bulk of a class named SawtoothOscillator1 that implements this technique. Although I use familiar bit integer samples for defining the waveform, internally XAudio2 uses bit floating point samples.
In the header file, a base frequency is set that divides cleanly into the 44, sampling rate. From that, a buffer size can be calculated that is the length of a single cycle of a waveform of that frequency:. This buffer is submitted to the IXAudio2SourceVoice with instructions that it should be repeated forever.
Without any further code, this is an oscillator that plays a Hz sawtooth wave forever. The argument to this is a frequency that the class uses to call SetFrequencyRatio. The range of human hearing—about 20 Hz to 20, Hz—is well within the bounds defined by those two constants applied to the base frequency of I must confess that I was initially somewhat skeptical of the SetFrequencyRatio method. Digitally increasing and decreasing the frequency of a waveform is not a trivial task.
I felt obliged to compare the results with a waveform generated algorithmically. This is the impetus behind the OscillatorCompare project, which is among the downloadable code for this column.
This second class has a SetFrequency method that controls how the class dynamically generates the samples that define the waveform. This waveform is continuously constructed in a buffer and submitted in real time to the IXAudio2SourceVoice object in response to callbacks. An instance of the class that implements this interface is then passed as an argument to the CreateSourceVoice method. In the XAudio2 documentation, this callback method is promoted as the one with the lowest latency, which is often highly desirable for interactive electronic music instruments.
The first constant is the length of the buffer used to submit waveform data. Here it functions as a circular buffer. The method responds by putting those bytes in the buffer starting from where it left off the last time and calling SubmitSourceBuffer just for that updated segment of the buffer.
It turns out that for a voice with a sample rate of 44, Hz, calls to OnVoiceProcessingPassStart always request bytes, or bit samples. Because PCM involves a constant sampling rate, low-frequency sounds seem to be sampled and rendered at a much higher resolution than high-frequency sounds. It turns out that any quantization distortion in PCM occurs at frequencies greater than half the sampling rate. One reason a sampling frequency of 44, Hz was chosen for CD audio is that the Nyquist frequency is 22, Hz, and human hearing maxes out at about 20, Hz.
In other words, at a sampling rate of 44, Hz, the quantization distortion is inaudible to humans. The SimpleAudio program generates an algorithmically simple waveform—a square wave at a frequency of Hz.
There are samples per cycle. In each cycle the first 50 are maximum positive values 32, when dealing with short integers and the next 50 are maximum negative values , Notice that these short values must be stored in the byte array with the low byte first:.
So far, nothing has actually played. This happens in the Click handler for the Button. If the Start method has already been called as it has in this example then the sound begins playing immediately. The SubmitSourceBuffer call returns immediately while a separate thread is devoted to the actual process of shoveling data to the sound hardware. Indeed, your program can manipulate these bytes as the sound is playing.
However, there are much better techniques involving callback methods that let your program dynamically generate sound data. You can press the button multiple times, and each call effectively queues up another buffer to be played when the previous buffer finishes. If the program moves to the background, the sound is muted but it continues to play in silence. In other words, if you click the button and move the program to the background for at least 5 seconds, nothing will be playing when the program returns to the foreground.
Much of the sound we hear in daily life comes simultaneously from a variety of different sources and, hence, is quite complex. However, in some cases—and particularly when dealing with musical sounds—individual tones can be defined with just a few characteristics:.
The SoundCharacteristics project demonstrates these four characteristics in isolation. No prior programming knowledge is required. Normally titles of foreign editions are similar to the English titles, but this one had to be changed because the pun no longer worked: The key of C in music is known as cis in German. The book is available from Amazon. A tutorial for programmers wishing to write applications for Windows using the C programming language and the Windows Forms class library.
A tutorial for programmers wishing to write applications for Windows using the C programming language and the native Win32 application programming interface API. Programs written using this book run under every version of Windows from Windows 95 through Windows XP and beyond.
0コメント