Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. cddump.c
  5. Abstract:
  6. dump cd tracks to wav files
  7. Environment:
  8. User mode only
  9. Revision History:
  10. 05-26-98 : Created
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <strsafe.h>
  15. #include "wav.h"
  16. ULONG32
  17. DumpWavHeader(
  18. HANDLE OutFile,
  19. ULONG32 Samples,
  20. ULONG32 SamplesPerSecond,
  21. USHORT Channels,
  22. USHORT BitsPerSample
  23. )
  24. {
  25. WAV_HEADER_CHUNK Header;
  26. ULONG32 temp;
  27. Header.ChunkId = ChunkIdRiff;
  28. Header.RiffType = RiffTypeWav;
  29. Header.Format.ChunkId = ChunkIdFormat;
  30. Header.Format.ChunkSize = sizeof(WAV_FORMAT_CHUNK) - (sizeof(ULONG)*2);
  31. Header.Format.FormatTag = FormatTagUncompressed;
  32. Header.Format.BitsPerSample = BitsPerSample;
  33. temp = (BitsPerSample+7)/8; // temp = bytes per sample rounded up
  34. Header.Format.Channels = Channels;
  35. temp *= Channels; // temp = bytes for all channels
  36. if (temp > (USHORT)-1) {
  37. fprintf(stderr, "Bytes for all channels exceeds MAXUSHORT, not a valid "
  38. "option for WAV file\n");
  39. return -1;
  40. }
  41. Header.Format.BlockAlign = (USHORT)temp;
  42. Header.Format.SamplesPerSec = SamplesPerSecond;
  43. Header.Format.AvgBytesPerSec = temp * SamplesPerSecond;
  44. temp *= Samples; // temp = number of total bytes
  45. temp *= 2; // unknown why this is needed.
  46. Header.Data.ChunkSize = temp;
  47. Header.Data.ChunkId = ChunkIdData;
  48. Header.ChunkSize = temp + sizeof(WAV_HEADER_CHUNK); // 54
  49. if (!WriteFile( OutFile, &Header, sizeof(Header), &temp, NULL ) ) {
  50. fprintf(stderr, "Unable to write header\n" );
  51. return -1;
  52. }
  53. return 0;
  54. }
  55. VOID
  56. ReadWavHeader(
  57. HANDLE InFile
  58. )
  59. {
  60. WAV_HEADER_CHUNK Header;
  61. ULONG temp;
  62. if (!ReadFile(InFile, &Header, sizeof(Header), &temp, NULL) ||
  63. temp != sizeof(Header)
  64. ) {
  65. fprintf(stderr, "Unable to read header %x\n", GetLastError());
  66. return;
  67. }
  68. if (Header.ChunkId != ChunkIdRiff) {
  69. printf("ChunkId is not RIFF (%x)\n", Header.ChunkId);
  70. return;
  71. }
  72. if (Header.RiffType != RiffTypeWav) {
  73. printf("RiffType is not RiffTypeWav (%x)\n", Header.RiffType);
  74. return;
  75. }
  76. if (Header.Format.ChunkId != ChunkIdFormat) {
  77. printf("Format.ChunkId is not ChunkIdFormat (%x)\n",
  78. Header.Format.ChunkId);
  79. return;
  80. }
  81. if (Header.Format.ChunkSize != sizeof(WAV_FORMAT_CHUNK) - (2*sizeof(ULONG))) {
  82. printf("Format.ChunkSize is not %x (%x)\n",
  83. sizeof(WAV_FORMAT_CHUNK) - (2*sizeof(ULONG)),
  84. Header.Format.ChunkSize);
  85. return;
  86. }
  87. if (Header.Format.FormatTag != FormatTagUncompressed) {
  88. printf("Format. is not Uncompressed (%x)\n", Header.Format.FormatTag);
  89. return;
  90. }
  91. if (Header.Data.ChunkId != ChunkIdData) {
  92. printf("Data.ChunkId is not ChunkIdData (%x)\n",
  93. Header.Data.ChunkId);
  94. return;
  95. }
  96. printf("Uncompressed RIFF/Wav File\n");
  97. printf("\t%2d bits per sample\n", Header.Format.BitsPerSample);
  98. printf("\t%2d channels\n", Header.Format.Channels);
  99. printf("\t%2d samples per second\n", Header.Format.SamplesPerSec);
  100. printf("\t%2d average bytes per second\n", Header.Format.AvgBytesPerSec);
  101. printf("Total data available to player: %d\n", Header.Data.ChunkSize);
  102. temp = Header.Data.ChunkSize / Header.Format.AvgBytesPerSec;
  103. printf("\t%d seconds of audio\n",
  104. temp
  105. );
  106. return;
  107. }