File: Sample.cxx

package info (click to toggle)
oonsoo 1.2-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,604 kB
  • ctags: 422
  • sloc: cpp: 24,373; makefile: 82
file content (74 lines) | stat: -rw-r--r-- 2,058 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
///////////////////////////////////////////////////////////////////////////////
// $Id: Sample.cxx,v 1.2 1996/01/03 20:17:59 bwmott Exp $
///////////////////////////////////////////////////////////////////////////////
//
// Sample.hxx - Sample class
//
//
// Bradford W. Mott
// Copyright (C) 1995
// January 4,1995
//
///////////////////////////////////////////////////////////////////////////////
// $Log: Sample.cxx,v $
// Revision 1.2  1996/01/03 20:17:59  bwmott
// Added include string.h
//
// Revision 1.1  1995/01/12 02:11:35  bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////

#include <string.h>
#include "Sample.hxx"

// Raw sample header
typedef struct {
  unsigned char lengthHB;
  unsigned char lengthMB;
  unsigned char lengthLB;
  unsigned char hertzMSB;
  unsigned char hertzLSB;
  unsigned char lengthOfName;
} RawSample;

///////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////
Sample::Sample(unsigned char* sampleData) 
{
  RawSample rawSample;

  // get the sample's header
  memcpy(&rawSample, sampleData, sizeof(rawSample));
  sampleData += sizeof(rawSample);

  // Get the length of the sample
  myLength = (((int)rawSample.lengthHB) << 16) +
      (((int)rawSample.lengthMB) << 8) + (int)rawSample.lengthLB;

  // Allocate space for the sample data
  myData = new unsigned char[myLength]; 

  memcpy(myData, sampleData, myLength);
  sampleData += myLength;

  // Get my name
  myName = new char[rawSample.lengthOfName + 1];
  memcpy(myName, sampleData, rawSample.lengthOfName);
  sampleData += rawSample.lengthOfName;
  myName[rawSample.lengthOfName] = '\0';
}

///////////////////////////////////////////////////////////////////////////////
// Destructor
///////////////////////////////////////////////////////////////////////////////
Sample::~Sample()
{
  // Free memory that holds my name
  delete[] myName;

  // Free image data
  delete[] myData;
}