File: square.c

package info (click to toggle)
snack 2.2.10-dfsg1-12.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,024 kB
  • sloc: ansic: 35,473; sh: 8,557; tcl: 1,065; python: 701; makefile: 565
file content (117 lines) | stat: -rw-r--r-- 2,811 bytes parent folder | download | duplicates (9)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* 
 * Copyright (C) 1997-2003 Kare Sjolander <kare@speech.kth.se>
 *
 * This file contains a sample module which demonstrates how to write
 * extensions to the Snack sound extension for Tcl/Tk.
 * The latest version of Snack can be found at http://www.speech.kth.se/snack/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "snack.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Windows magic */

#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#define EXPORT(a,b) __declspec(dllexport) a b
BOOL APIENTRY
DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
  return TRUE;
}
#else
#define EXPORT(a,b) a b
#endif

int
Square(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
  Sound *sound;
  int i;

  /* Get the sound structure for this sound */
      
  sound = Snack_GetSound(interp, Tcl_GetStringFromObj(objv[0], NULL));

  /* create a simple square wave */

  for (i = 0; i < Snack_GetLength(sound); i++) {
    if ((i/10)%2) {
      Snack_SetSample(sound, 0, i, 10000.0f);
    } else {
      Snack_SetSample(sound, 0, i, -10000.0f);
    }
  }

  /* update the max/min members of the sound structure */

  Snack_UpdateExtremes(sound, 0, sound->length, SNACK_NEW_SOUND);

  /* execute callbacks for stuff like canvas items */

  Snack_ExecCallbacks(sound, SNACK_NEW_SOUND);

  return TCL_OK;
}

/*
  Initialize the square package and create a new sound command 'square'.
  The syntax is: sndName square
 */

EXPORT(int, Square_Init)(Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
  if (Tcl_InitStubs(interp, "8", 0) == NULL) {
    return TCL_ERROR;
  }
#endif

#ifdef USE_TK_STUBS
    if (Tk_InitStubs(interp, "8", 0) == NULL) {
      return TCL_ERROR;
    }
#endif

#ifdef USE_SNACK_STUBS
  if (Snack_InitStubs(interp, "2", 0) == NULL) {
    return TCL_ERROR;
  }
#endif

  if (Tcl_PkgProvide(interp, "square", "1.0") != TCL_OK) {
    return TCL_ERROR;
  }

  Snack_AddSubCmd(SNACK_SOUND_CMD, "square", (Snack_CmdProc *) Square, NULL);

  return TCL_OK;
}

EXPORT(int, Square_SafeInit)(Tcl_Interp *interp)
{
  return Square_Init(interp);
}

#ifdef __cplusplus
}
#endif